Why can I not plot two simple vectors? Matlab keeps returning "too many input arguments" Help!
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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?
More Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!