MATLAB: How to plot for different values of parameters on one run

3d plotsfigureode45plotplottingsubplot

How to get the plots for different values of aplha = 2,3,4,5 on one run and how to merge all those graphs ?
function [t,y] = call_dstate()
tspan = [0 9]; % set time interval
y0 = 10; % set initial condition
% dstate evaluates r.h.s. of the ode
[t,y] = ode45( @dstate ,tspan ,y0);
plot(t,y)
disp([t,y]) % displays t and y(t)
function dydt = dstate (t,y)
alpha=2; gamma=0.0001;
dydt = alpha* y-gamma *y^2;
end
end

Best Answer

Matlab actually has a page on this called Parameterizing Functions.
Using one of the options for that I believe this will do it for you. This works because the nested function can use variables created in the outer function.
function [t,y] = call_dstate()
tspan = [0 9]; % set time interval
y0 = 10; % set initial condition
% dstate evaluates r.h.s. of the ode
gamma=0.0001;
for alpha = 2:5
[t,y] = ode45( @dstate ,tspan ,y0);
plot(t,y); hold on;
end
disp([t,y]) % displays t and y(t)
function dydt = dstate (t,y)
dydt = alpha* y-gamma *y^2;
end
end