我的主程序是
function [z,k] = newton(y0,n,eps1)
k=1;
z=y0;
t=y0-fun0(y0)./dfun0(y0);
while abs(t-y0)>=eps1
z=[z,t];
y0=t;
k=k+1;
t=y0-fun0(y0)./dfun0(y0);
if (k-1)>n
error('n is full');
end
end
end
其中调用了fun0和dfun0两个函数,funo函数程序为
function [fun] = fun0(y)
fun=49550.*log(5000000) - 49550.*log(y - (y.*exp(y./17520000))./25 + 5000000) - (1238750.*((5000000.*log(y + 5000000))./exp(y./17520000) - (5000000.*log(y - (y.*exp(y./17520000))./25 + 5000000))./exp(y./17520000)))./y + ((991.*y)./2 + 100).*((2500.*(5000000./(exp(y./17520000).*(y + 5000000)) - (125.*log(y + 5000000))./(438.*exp(y./17520000)) + (125.*log(y - (y.*exp(y./17520000))./25 + 5000000))./(438.*exp(y./17520000)) + (5000000.*(exp(y./17520000)./25 + (y.*exp(y./17520000))./438000000 - 1))./(exp(y./17520000).*(y - (y.*exp(y./17520000))./25 + 5000000))))./y - (2500.*((5000000.*log(y + 5000000))./exp(y./17520000) - (5000000.*log(y - (y.*exp(y./17520000))./25 + 5000000))./exp(y./17520000)))./y.^2 + 2500./(exp(y./17520000).*(y + 5000000)) - (100.*(exp(y./17520000)./25 + (y.*exp(y./17520000))./438000000 - 1))./(y - (y.*exp(y./17520000))./25 + 5000000) - log(y + 5000000)./(7008.*exp(y./17520000)) + log(y - (y.*exp(y./17520000))./25 + 5000000)./(7008.*exp(y./17520000)) + (2500.*(exp(y./17520000)./25 + (y.*exp(y./17520000))./438000000 - 1))/(exp(y./17520000).*(y - (y.*exp(y./17520000))./25 + 5000000))) - (1238750.*log(y + 5000000))./exp(y./17520000) + (1238750.*log(y - (y.*exp(y./17520000))./25 + 5000000))./exp(y./17520000) + 49550;
end
运行结果为
》[z,k] = newton(2000,40,0.0001)
??? Undefined function or method 'ge' for input arguments of type 'sym'.
Error in ==> newton at 5
while abs(t-y0)>=eps1