Reputation: 3
Currently I'm trying to learn about numerical methods, which involves a lot of matlab, there is an example in the book which I would love to use, but it simply wont work, it's looking like this:
function [t,y]=euler(inter,y0,n)
t(1)=inter(1);
y(1)=y0;
h=(inter(2)-inter(1))/n;
for i=1:n
t(i+1)=t(i)+h;
y(i+1)=eulerstep(t(i),y(i),h);
end
plot(t,y)
function y=eulerstep(t,y,h)
y=y+h*ydot(t,y);
function z=ydot(t,y)
z=t*y+t.^3;
And I'm trying to run all of it with only the usage of euler([0 1],1,10);
But when I try to run it, I get the warning;
Too many input arguments.
Where did everything go wrong? And help at this point is greatly appreciated!
Upvotes: 0
Views: 138
Reputation: 19689
euler
is also a built-in function. Save your m-file with a different name, say euler11
and change the name of euler
function to something else, say euler11
. And then try again by calling it with euler11([0 1],1,10);
Making these changes gives me this output:
The lesson to learn or the good programming practice is to never name your variables/functions with the name of built-in ones.
Upvotes: 3