Clear Filters
Clear Filters

Plotting help

3 views (last 30 days)
John
John on 27 Mar 2011
I want to plot an anonymous function on the same plot of a numerical euler's method solution to a problem. My code is below (I have both plots working but I want them to be on the same plot not 2 separate plots)
%%Analytical
simplify(dsolve('Dy=-x/y','y(0)=5','x'))
%%Numerical
f=@(x) (-x^2+25)^(1/2);
dydx=@(x,y) -(x/y);
[x1,y1]=eulode(dydx, [0 1],5,.5);
[x2,y2]=eulode(dydx,[0 1],5,.1);
[x3,y3]=eulode(dydx,[0 1],5,.01);
disp([x1,y1])
disp([x2,y2])
disp([x3,y3])
%%Plot
plot(x1,y1,'k',x2,y2,'b',x3,y3,'g','linewidth',2)
figure(2)
fplot(f,[0 5],'linewidth',2,'k')

Accepted Answer

Paulo Silva
Paulo Silva on 27 Mar 2011
replace figure(2) by
hold on

More Answers (0)

Categories

Find more on Visual Exploration 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!