【发布时间】:2013-10-21 13:30:45
【问题描述】:
我需要在Matlab上写一个牛顿法代码并通过这里处理。但是当我尝试使用它时,它在计算了几次后给出了这个错误:
尝试访问 df(8);索引超出范围,因为 数字(df)=1。
newton 方法中的错误(第 11 行) tz=ti-(f(ti)/df(ti));
function newtonmethod(f)
ti = 10;
tz = 8;
abstol = 0.0001;
counter = 0;
h=0.1;
df=((f(ti+h)-f(ti))/h);
while (abs(ti-tz)>abstol)
ti=tz;
tz=ti-(f(ti)/df(ti));
counter=counter+1;
end
ti=tz;
fprintf(tz,'counter=',counter )
end
我该怎么办?
【问题讨论】:
标签: matlab