【发布时间】:2019-06-19 19:15:16
【问题描述】:
我正在尝试在Matlab中应用牛顿法,我写了一个脚本:
syms f(x)
f(x) = x^2-4
g = diff(f)
x_1=1 %initial point
while f(['x_' num2str(i+1)])<0.001;% tolerance
for i=1:1000 %it should be stopped when tolerance is reached
['x_' num2str(i+1)]=['x_' num2str(i)]-f(['x_' num2str(i)])/g(['x_' num2str(i)])
end
end
我收到此错误:
Error: An array for multiple LHS assignment cannot contain M_STRING.
牛顿法公式是 x_(n+1)= x_n-f(x_n)/df(x_n),直到 f(x_n) 值接近零。
【问题讨论】:
-
请不要创建动态变量。使用单个数组保留所有迭代
标签: matlab newtons-method