Newton's Method error message

7 ビュー (過去 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 Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by