个人工具
登录
查看“Maxima简介”的源代码 - Ubuntu中文
页面
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“Maxima简介”的源代码
来自Ubuntu中文
←
Maxima简介
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==Maxima编程== 到现在为止,我们都是在交互模式下使用的 Maxima,使用过程象个计算器一样,然而,对于那些需要多次调用的计算过程,还是编写一个自定义函数来得方便。这里我们展示了一个简短的自定义函数,用来计算二元函数 f(x,y) 的极值点。这个程序提示用户输入函数 f,之后就会计算 fx 和 fy 的偏导数,接着调用 Maxima 命令 solve 去得到 fx=fy=0的解。这个程序在 Maxima 之外用一个文本编辑器编写,然后用 batch 命令装载进 Maxima。下面是程序列表: /* -------------------------------------------------------------------------- this is file critpts.max: as you can see, comments in maxima are like comments in C Nelson Luis Dias, nldias@simepar.br created 20000707 updated 20000707 --------------------------------------------------------------------------- */ critpts():=( print("program to find critical points"), /* --------------------------------------------------------------------------- asks for a function --------------------------------------------------------------------------- */ f:read("enter f(x,y)"), /* --------------------------------------------------------------------------- echoes it, to make sure --------------------------------------------------------------------------- */ print("f = ",f), /* --------------------------------------------------------------------------- produces a list with the two partial derivatives of f --------------------------------------------------------------------------- */ eqs:[diff(f,x),diff(f,y)], /* --------------------------------------------------------------------------- produces a list of unknowns --------------------------------------------------------------------------- */ unk:[x,y], /* --------------------------------------------------------------------------- solves the system --------------------------------------------------------------------------- */ solve(eqs,unk) )$ 这个程序 (实际上是个没有参数的函数) 叫做 critpts。每一行都是一个有效的 Maxima 语句,由逗号隔开。偏导数被保存在一个叫做 eqs 的变量中。未知数保存在变量 unk 中。以下是运行示例: (%i1) batch ("critpts.max"); batching #p/home/robert/tmp/maxima-clean/maxima/critpts.max (%i2) critpts() := (print("program to find critical points"), f : read("enter f(x,y)"), print("f = ", f), eqs : [diff(f, x), diff(f, y)], unk : [x, y], solve(eqs, unk)) (%i3) critpts (); program to find critical points enter f(x,y) %e^(x^3 + y^2)*(x + y); 2 3 y + x f = (y + x) %e (%o3) [[x = 0.4588955685487 %i + 0.35897908710869, y = 0.49420173682751 %i - 0.12257873677837], [x = 0.35897908710869 - 0.4588955685487 %i, y = - 0.49420173682751 %i - 0.12257873677837], [x = 0.41875423272348 %i - 0.69231242044203, y = 0.4559120701117 - 0.86972626928141 %i], [x = - 0.41875423272348 %i - 0.69231242044203, y = 0.86972626928141 %i + 0.4559120701117]]
返回至
Maxima简介
。