Why can I not plot two simple vectors? Matlab keeps returning "too many input arguments" Help!

1 view (last 30 days)
function [t,y] = Euler(h)
% Simple Euler integration method for the Ordinary Differential Equation
%
% dy/dt = f(t,y), initial condition: y(1) [see below]
%
% with stepsize h. t and y are vector-valued outputs for the solution
% y at time t.
Tmax = 1; % final time
f = @(t,y) -3.*y;
y(1) = 1;
t = [0:h:Tmax]; % h is the stepsize: make sure Tmax is divisible by h!
for i=1:length(t)-1
y(i+1) = y(i) + h*f(t(i),y(i));
end
figure
plot(t,y)
end

Accepted Answer

the cyclist
the cyclist on 12 Dec 2015
I saved your code to a file named Euler.m, and then called it with
Euler(0.1)
and it ran just fine. Is that what you are doing?
What is the output of
which Euler
?
Maybe you defined Euler as both a variable and a function?
  1 Comment
Cole Hayden
Cole Hayden on 12 Dec 2015
This is what it gave me when I input what you suggested.
>> which Euler
/Users/****/Downloads/Euler.m (this is my folder containing the file)
>> [t,y] = Euler(0.1)
Error using plot
Too many input arguments.
Error in Euler (line 20)
plot(t,y)
I have a feeling it has something to do with my computer. I've had this problem before. I'm using a code provided that worked in the computer labs on campus. But for some reason the same code on my personal computer is returning this error? Do you have any suggestions? Maybe my pathway or folder or something...? Thanks

Sign in to comment.

More Answers (1)

Cole Hayden
Cole Hayden on 12 Dec 2015
Actually, turns out I had a file on my computer called "plot.m"......... -____- thanks for your help though. Your suggestion kind of got me thinking if I had a function of that sort.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!