Newton's Method error message

조회 수: 1 (최근 30일)
Kylee Crise
Kylee Crise 2019년 11월 1일
답변: Jim Riggs 2019년 11월 1일
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);

답변 (1개)

Jim Riggs
Jim Riggs 2019년 11월 1일
The variable x is not defined in
w(n+1) = w(n) - (z(w(n))/dz(x(n)));

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by