How I can correct this error? "Undefined operator '/' for input arguments of type 'function_handle'."
Show older comments
I'm trying to solve system of non-linear equation using Newton raphson method.
I'm coded right, but it keep me saying "Undefined operator '/' for input arguments of type 'function_handle'."
Any one can help me with it? The error is on line 19.
Heres the full code:
This code used to generate Jacobian vector.
function J=Derivative(F,x,xi,i)
e=0.001;
x1=x;
x2=x;
x1(i)=xi;
x2(i)=xi+e;
J=(F(x2)-F(x1))/e;
end
This is the full code I,m try to solve. In this code I have 8 system of equation, which are 5 of them are non-linear and 3 of them are linear.
%newton raphson method
clc
clear all
R=0.314;
T=1000;
z=@(x) x(1)+x(2)+x(3)+x(4)+x(5);
F1=@(x) 19720+(R*T*log(x(1)/z))-x(6)-4*x(7);
F2=@(x) -1920420+(R*T*log(x(2)/z))-2*x(7)-x(8);
F3=@(x) -200240+(R*T*log(x(3)/z))-x(6)-x(8);
F4=@(x) -395790+(R*T*log(x(4)/z))-x(6)-2*x(8);
F5=@(x) (R*T*log(x(2)/z))-2*x(7);
F6=@(x) x(1)+x(3)+x(4)-2;
F7=@(x) 4*x(1)+2*x(2)+2*x(5)-14;
F8=@(x) x(2)+x(3)+2*x(4)-3;
x=[0.25; 0.198; 0.222; 0.78; 0.7892; 2000; 3000; 5000];
for i=1:10
F = [F1(x);F2(x);F3(x);F4(x);F5(x);F6(x);F7(x);F8(x)]; %The error is on this line
for k=nume1(x)
for j=numel(x)
Jacobian(k,j)=Derivative(eval(['F' num2str(k)]),x,x(j),j);
end
end
x=x-inv(Jacobian)*F;
end
2 Comments
madhan ravi
on 21 Sep 2020
there's already an inbuilt function named as jacobian() , you have spelling error in j = nume1() should be numel() , after defining z , replace the other z's with z(x).
tolossa kebede
on 22 Sep 2020
Accepted Answer
More Answers (0)
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!