Quantcast
Viewing all articles
Browse latest Browse all 164

Printing the Jacobian at each iteration (Newton's method for a nonlinear system)

Dear all,
Greetings!
I have made a code that solves a nonlinear system of equations by using Newton's Method. I am facing a problem in printing the Jacobian at each iteration. It only prints its lable not the Jacobian matrix itself. Please help me in this regard.
 

Image may be NSFW.
Clik here to view.
"restart;  iter:=5;  f[1](x,y):=3 x^(2)-y^(2);  f[2](x,y):=3 x^()*y^(2)-x^(3)-1;"

Image may be NSFW.
Clik here to view.
5

 

Image may be NSFW.
Clik here to view.
proc (x, y) options operator, arrow; 3*x^2-y^2 end proc

 

Image may be NSFW.
Clik here to view.
proc (x, y) options operator, arrow; 3*x*y^2-x^3-1 end proc

(1)

Image may be NSFW.
Clik here to view.
var := x, y

Image may be NSFW.
Clik here to view.
x, y

(2)

Image may be NSFW.
Clik here to view.
pointt := [x[n], y[n]]

Image may be NSFW.
Clik here to view.
[x[n], y[n]]

(3)

Image may be NSFW.
Clik here to view.
NULL

Image may be NSFW.
Clik here to view.
NULL

Image may be NSFW.
Clik here to view.
NULL

Image may be NSFW.
Clik here to view.
x[0] := 1; y[0] := 1

Image may be NSFW.
Clik here to view.
1

 

Image may be NSFW.
Clik here to view.
1

(4)

Image may be NSFW.
Clik here to view.
for n from 0 to iter do print('f1' = f[1](x[n], y[n]), 'f[2]' = f[2](x[n], y[n])); print('J'*[n] = J[n]); J[n] := Student[MultivariateCalculus][Jacobian]([f[1](x, y), f[2](x, y)], [var] = pointt, output = matrix); sol[n] := eval((Vector(2, {(1) = x[n], (2) = y[n]}))-1/J[n].(Vector(2, {(1) = f[1](x[n], y[n]), (2) = f[2](x[n], y[n])}))); x[n+1] := evalf(sol[n][1]); y[n+1] := evalf(sol[n][2]); print(x[n+1], y[n+1]) end do

Image may be NSFW.
Clik here to view.
f1 = 2, f[2] = 1

 

Image may be NSFW.
Clik here to view.
J*[0] = J[0]

 

Image may be NSFW.
Clik here to view.
.6111111111, .8333333333

 

Image may be NSFW.
Clik here to view.
f1 = .4259259256, f[2] = 0.44924554e-1

 

Image may be NSFW.
Clik here to view.
J*[1] = J[1]

 

Image may be NSFW.
Clik here to view.
HFloat(0.5036590808700434), HFloat(0.8524944221287727)

 

Image may be NSFW.
Clik here to view.
f1 = HFloat(0.03427066946790058), f[2] = HFloat(-0.029666658033242088)

 

Image may be NSFW.
Clik here to view.
J*[2] = J[2]

 

Image may be NSFW.
Clik here to view.
HFloat(0.4999641210723523), HFloat(0.8660456363859079)

 

Image may be NSFW.
Clik here to view.
f1 = HFloat(-1.4267722412308892e-4), f[2] = HFloat(-1.2576398193964167e-6)

 

Image may be NSFW.
Clik here to view.
J*[3] = J[3]

 

Image may be NSFW.
Clik here to view.
HFloat(0.50000000001492), HFloat(0.8660254018170033)

 

Image may be NSFW.
Clik here to view.
f1 = HFloat(3.45245787514159e-9), f[2] = HFloat(-5.089167087746205e-9)

 

Image may be NSFW.
Clik here to view.
J*[4] = J[4]

 

Image may be NSFW.
Clik here to view.
HFloat(0.5), HFloat(0.8660254037844386)

 

Image may be NSFW.
Clik here to view.
f1 = HFloat(1.1102230246251565e-16), f[2] = HFloat(-2.220446049250313e-16)

 

Image may be NSFW.
Clik here to view.
J*[5] = J[5]

 

Image may be NSFW.
Clik here to view.
HFloat(0.5), HFloat(0.8660254037844387)

(5)

Image may be NSFW.
Clik here to view.
NULL

Image may be NSFW.
Clik here to view.
NULL


 

Download q1nwtnnonlinearsys.mw

the print output is too ugly, any help in making it more elegant would also be appreciated .


Viewing all articles
Browse latest Browse all 164

Trending Articles