[英]Matlab error on code
我在運行此代碼時遇到問題,由於“{”括號而出現錯誤,但由於我對 MATLAB 沒有太多經驗,因此無法找到修復它們的方法。 我知道這與括號有關,而且似乎我在某處缺少結尾。
f=@(x) x^3
a=1;
b=3;
tol=0.00005;
for i=1:100
c=(a+b)/2;
if(c<tol){
break;
}
if f(c)>0
b=c;
else
a=c;
end
end
a=1;
b=3;
p=c;
for i=1:100
c=(a+b)/2;
if(c<tol){
break;
}
er(i)=f(c)-f(p);
if f(c)>0
b=c;
else
a=c;
end
end
fprintf('Calculated Root is %f',c)
plot(er);
title('Plot of error')
xlabel('Number of iterations')
ylabel('Error')
我只能猜測你的意思,但你想要的可能是
f=@(x) x^3
a=1;
b=3;
tol=0.00005;
for i=1:100
c=(a+b)/2;
if c<tol
break;
end
if f(c)>0
b=c;
else
a=c;
end
end
a=1;
b=3;
p=c;
for i=1:100
c=(a+b)/2;
if c<tol
break;
end
er(i)=f(c)-f(p);
if f(c)>0
b=c;
else
a=c;
end
end
fprintf('Calculated Root is %f',c)
plot(er);
title('Plot of error')
xlabel('Number of iterations')
ylabel('Error')
您可能應該快速瀏覽一些簡短的 Matlab 介紹,以了解 Matlab 代碼的外觀。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.