Newton's Method error message
Show older comments
I keep recieving this error code and I don't know how to fix it or if it will even work after i fix it. The initial value is supposed to be 20 and the threshold is 0.1.
Index exceeds the number of array elements (0).
Error in EE291_Pr01_crise_kylee_part2 (line 17)
w(n+1)= w(n)-(z(w(n))/dz(x(n)));
clc;
clear;
z=@(w) (100+(0.5*w/(.0000003*w^2+1)));
c=0.0000003;
a=50000000;
b=10000000;
dz=@(w) (a*(3*w^2-b))/((3*w^2+b)^2);
w0=20;
w(1)=w0;
thr=0.1;
err=1;
n=0;
w=zeros(0, 10000000);
while err>=1e-1
%set while-conditions
n=n+1;
w(n+1)= w(n)-(z(w(n))/dz(x(n)));
%compute next iterate
err=abs((w(n+1)-w(n))/w(n+1))*100;
%compute error
end
disp(n);
disp(w);
disp(err);
Answers (1)
Jim Riggs
on 1 Nov 2019
0 votes
The variable x is not defined in
w(n+1) = w(n) - (z(w(n))/dz(x(n)));
Categories
Find more on Systems of Nonlinear Equations 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!