x1
和x2
很复杂。示例:x1 = x1reel+x1img*i
和x2 = x2reel-x2img*i
。 x0
是第一个价值和复杂的。
clc
clear all
% Define the given function
syms x1 x2
x=[x1,x2];
f(x)=[3*x1-cos(x1^2)-1/2;3*x2-cos(x2^2)-1/2];
% Define the stopping criteria based on Nither or relative errors
tol=10^-5;
Niter=100;
df=jacobian(f,x);
x0=[complex;complex];
% Setting starting values
error=1;
i=0;
% Start the Newton-Raphson Iteration
while(abs(error)>tol)
f0=eval(f(x0(1),x0(2)));
df0=eval(df(x0(1),x0(2)));
xnew=x0-df0\f0; % also tried lsqr(df0,f0),bicg(df0,f0)
error=norm(xnew-x0);
x0=xnew;
i=i+1
if i>=Niter
fprintf('Iteration times spill over Niter\n');
return;
end
end
我想做Newton-Raphson Iteration。但我很难,因为它很复杂。