跳转到内容

Maxima/数值方法

来自维基教科书,开放的书籍,开放的世界
 "If you are doing purely numerical computation and are concerned about speed, use a compiled numerical programming language. Maxima is intended for use if you have symbolic mathematical symbols, too,
 and while it works for numbers, most components of the system are on the lookout for non-numeric inputs, and this checking takes time. 
 It is possible to speed up certain kinds of numeric computations in Maxima by using compile() and mode_declare()  together. " RJF


牛顿法

[编辑 | 编辑源代码]

函数

  • newton 用于单变量函数方程
  • mnewton 是牛顿法求解一个或多个变量的非线性方程的实现。

加载

load("newton");
(%o1)                                                                                                   /home/a/maxima/share/numeric/newton.mac
(%i2) load("newton1");
(%o2)                                                                                                   /home/a/maxima/share/numeric/newton1.mac

代码

/* 
 
Maxima CAS code 
from /maxima/share/numeric/newton1.mac 
input : 
 exp  =  function of one variable, x
 var = variable 
 x0 = initial value of variable
 eps = 

The search begins with x = x_0 and proceeds until abs(expr) < eps (with expr evaluated at the current value of x). 

output : xn = an approximate solution of expr = 0 by Newton's method
*/ 


newton(exp,var,x0,eps):=
block(
  [xn,s,numer],
   numer:true,
   s:diff(exp,var),
   xn:x0,
   
   loop, 
    if abs(subst(xn,var,exp))<eps 
         then return(xn),
    xn:xn-subst(xn,var,exp)/subst(xn,var,s),
   go(loop) 
)$


通过牛顿法确定曼德尔布罗特集合的边界。图像和 Maxima CAS 代码

可以使用牛顿法求解多个非线性函数的系统。它在 mnewton 函数中实现。请参阅目录

/Maxima..../share/contrib/mnewton.mac

该目录使用在以下定义的 linsolve_by_lu

 /share/linearalgebra/lu.lisp

请参阅 此图像 以获取更多代码。

(%i1) load("mnewton")$

(%i2) mnewton([x1+3*log(x1)-x2^2, 2*x1^2-x1*x2-5*x1+1],
              [x1, x2], [5, 5]);
(%o2) [[x1 = 3.756834008012769, x2 = 2.779849592817897]]
(%i3) mnewton([2*a^a-5],[a],[1]);
(%o3)             [[a = 1.70927556786144]]
(%i4) mnewton([2*3^u-v/u-5, u+2^v-4], [u, v], [2, 2]);
(%o4) [[u = 1.066618389595407, v = 1.552564766841786]]
华夏公益教科书