Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Why do I get NaN result?

3 ビュー (過去 30 日間)
Ludvig Hultman
Ludvig Hultman 2020 年 10 月 12 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi,
When I'm using the steepest descent method I have a hard time getting the result on the x:cordinate.
In the code below, the issue arises in "gradf". Can someone help me?
n=0; %initialize iteration counter
eps=1; %initialize error
a=0.04; %set iteration parameter
x=[-1;-1]; %set starting value
%Computation loop
while eps>0.5e-4&n<100
gradf=[3*x(1)^2+0.8*x(1)+2.8*x(2); 2.8*(x(1))+2.7*(x(2))^2-1.1]; %gradf(x)
eps=abs(gradf(1))+abs(gradf(2)); %error
y=x-a*gradf; %iterate
x=y; %update x
n=n+1; %counter+1
end
n,x,eps, %display end values

回答 (1 件)

Sudhakar Shinde
Sudhakar Shinde 2020 年 10 月 12 日
Values within gradf function for n=32 becomes infinite ('inf') and hence results are NAN (Not a number).

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by