I want to return two array in this function(newton method). But when I run this script in matlab. It will only return the first array. How should I fix it?
function [iter errorn]=Newton(func,dfunc,x0)
i=1;
solution=fzero(func,x0);
while abs(x0-solution)>1e-06
iter(i)=i;
x0=x0-func(x0)./dfunc(x0);
errorn(i)=abs(x0-solution);
i=i+1;
end
end
The function is called by:
f1=@(x)x^3-2*x-5;
df1=@(x)3*x^2-2;
[iter,y1N]=Newton(f1,df1,4)
But MATLAB returns an error: too many arguments
iterandy1N. what more do you want?which Newtonand verify that this is the path to yourNewtonfunction.