function[ans]=newton(fun,a,count,e)
%此函式用于求解方程的根;
%用牛頓迭代法,f是目標方程,a為起始點,count為最大迭代次數,e為精度;
syms x;
df=diff(fun(x));
x0=a;
for(i=1:count)
x1=x0-fun(x0)/subs(df,x0);
if(abs(x1-x0)>e)
x0=x1;
end
end
ans=x0;
錯誤使用 sym/subsindex (line 825)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be
symbolic variables, and function body must be sym expression.
出錯 newton (line 5)
df=diff(fun(x));
一直這種跳錯,希望大家幫我看看問題是什么
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/65321.html
標籤:其他開發語言
