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));endfigureplot(t,y)end
MATLAB: Can I not plot two simple vectors? Matlab keeps returning “too many input arguments” Help!
argumentserrorinputplotplotting
Best Answer