跳轉到內容

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]]
華夏公益教科書