MATLAB: Plotting help

function handleplot

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')

Best Answer

replace figure(2) by
hold on