필터 지우기
필터 지우기

Non linear Newton iteration method

조회 수: 2 (최근 30일)
Syed Abdul Rafay
Syed Abdul Rafay 2022년 10월 27일
편집: Jan 2022년 10월 29일
Can anyone tell me problem in this code? i want to solve newton Iteration method where
X(i+1) = x(i)-Jcbi inv*F(i)
function NL_Newtons_Iteration(x0,y0,TC)
Tstart = cputime;
if nargin<4, x0=0; y0=0; z0=0; TC=10^-4; end
x1(1)=x0; x2(1)=y0; x3(1)=z0; i=0; error=TC+1;
X{1}=[x1(1); x2(1); x3(1)];
while(error>TC)
Jcbi=jacobian([F1,F2,F3],[x1,x2,x3]);
Jcbi_inv=inv(Jcbi);
X{i+2}=X{i+1}-Jcbi_inv*[F1(x1(i+1), x2(i+1), x3(i+1)); F2(x1(i+1), x2(i+1), x3(i+1)); F3(x1(i+1), x2(i+1), x3(i+1))];
Ex=100*abs((x1(i+1)-x1(i))/x1(i+1));
Ey=100*abs((x2(i+1)-x2(i))/x2(i+1)); %if 3 variables: E=[Ex Ey Ez];error=max(E)
Ez=100*abs((x3(i+1)-x3(i))/x3(i+1));
E=[Ex Ey Ez];
error=max(E);
i=i+1;
end
fprintf('After %d iterations an approimate solution is',i);
soln=[x1(i+1); x2(i+1); x3(i+1)]
TEnd = cputime - Tstart
end
function F1=F1(x1,x2,x3)
F1=((-3/5)*x1)+((1/4)*x2)+((1/4)*cos(x3))+1.43;
end
function F2=F2(x1,x2,x3)
F2=((1/4)*x1)-((3/5)*x2)-((1/4)*sin(x3))-1.24;
end
function F3=F3(x1,x2,x3)
F3=((1/4)*sin(x1))-((1/4)*exp(-x2))-((3/5)*x3)-1.17;
end
I am getting errors when I run the code. The x1 x2 x3 are x y z.
  댓글 수: 1
Syed Abdul Rafay
Syed Abdul Rafay 2022년 10월 29일
Not enough input arguments.
Error in test>F1 (line 22)
F1=((-3/5)*x1)+((1/4)*x2)+((1/4)*cos(x3))+1.43;
Error in test (line 7)
Jcbi=jacobian([F1,F2,F3],[x1,x2,x3]);
These are the errors

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2022년 10월 29일
편집: Jan 2022년 10월 29일
Similar to your other question, [F1,F2,F3] is not a function handle, but a vector. Here you call F1, F2 and F3 without inputs.
Better:
function Y = F123(x1,x2,x3)
Y = [((-3/5)*x1)+((1/4)*x2)+((1/4)*cos(x3))+1.43; ...
((1/4)*x1)-((3/5)*x2)-((1/4)*sin(x3))-1.24; ...
((1/4)*sin(x1))-((1/4)*exp(-x2))-((3/5)*x3)-1.17];
end
And in the loop:
Jcbi = jacobian(@F123, [x1,x2,x3]); % Failing!
But this still does not match the needs of the jacobian function, which requires symbolic input.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by