Array indices must be positive integers or logical values
Show older comments
clc
f1= (-(3/5)*X(1))+((1/4)*X(2))+((1/4)*cos(X(3)))+1.43;
f2= ((1/4)*X(1))-((3/5)*X(2))-((1/4)*sin(X(3)))-1.24;
f3= ((1/4)*sin(X(1)))-((1/4)*exp(-X(2)))-((3/5)*X(3))-1.17;
F= [f1;f2;f3];
%J= jacobian([f1,f2,f3],[X(1),X(2),X(3)]);
J = [(-3/5) (1/4) (-1/4)*sin(X(3));
1/4 -3/5 (-1/4)*cos(X(3));
(1/4)*cos(X(1)) (1/4)*exp(-X(2)) -3/5];
x0=0; %initial guess
y0=0;
z0=0;
X = [x0;y0;z0];
TC=10^-8;
i = 0;
i_max = 100;
while(error>TC)
i=i+1;
X0=X;
X = X0 - J(X0)\F(X0);
error = max(abs(X-X0));
end
if i>i_max
disp('No solutions are found');
else
disp(['x = ',num2str(X(1))])
disp(['y = ',num2str(X(2))])
disp(['z = ',num2str(X(3))])
disp(error)
end
I get error
" Array indices must be positive integers or logical values. "
Can someone help me where is the problem?
also can you help me with J= jacobian([f1,f2,f3],[X(1),X(2),X(3)])? when I run this with upper code it give me error of incorrect arrangement
1 Comment
Jan
on 29 Oct 2022
Please post the complete error message. Then the readers do not have to guess, in which line the error occurs.
We cannot run your code due to the missing inputs, so it would be a good idea to post all details you have in the command line available already.
"it give me error of incorrect arrangement" - see above: Post a copy of the message instead of a rough paraphrasation.
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differentiation 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!