Plotting help

3 次查看(过去 30 天)
John
John 2011-3-27
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')

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by