I have the following matlab code for approximating a differential equation via the Euler-method:
% Eulermethod
a=0;
b=0.6;
Steps=6;
dt=(b-a)/Steps;
x=zeros(Steps+1,1);
x(1,1)=1;
y=zeros(Steps+1,1);
for i=1:Steps
x(i+1,1)=x(i,1)+dt*(x(i,1)*x(i,1)+1);
end
plot(x)
I want to be able to plot the solution plot for several different values of Steps in one plot and have the x-axis go from 0 to 0.6 instead of from for example 1 to 100 000 etc. Can this be done?
If you use the
hold oncommand this will allow you achieve multiple plots on the same figure. Similarly, if you separate your data intoxandyvectors, you can plot them against eachother by passing 2 vectors toplotinstead of just one. For exampleYou should now see all your plots simultanesously on the same figure. If you want
xto be composed ofnequally spaced elements between 0 and 0.6, you could use thelinspacecommand:In order to distinguish your plots, you can pass an extra paramter to the function .For example
will plot the data as a series of red
+symbols.