How do I plot this?
显示 更早的评论
Hi I have used bvp4c to find a numerical solution to a problem. I want to be able to plot this numerical solution on a graph as well as the analytical solution, but have no idea how to do this. Any help would be grealy appreciated.
Code:
init: if true % function v=init(x) v=[2*x+pi^2/2 1-4*x/pi 4*x/pi 2*x/pi]; end
odefun: if true % function dyds_tilde=odefun(x,s_tilde,a) p=1; dyds_tilde=[(p/(a-1))*a a*cos(s_tilde(2 a*sin(s_tilde(2)) a ]; end
bcfun:
if true
% function res=bc(s_tilde0,s_tilde1,a)
res=[s_tilde0(4)
s_tilde0(2)
s_tilde0(3)
s_tilde1(1)-pi
s_tilde1(2)];
end
bvp: if true % a=0.25; solinit=bvpinit(linspace(0,1),@init,a); sol=bvp4c(@odefun, @bcfun, solinit) fprintf('a = %g. \n', sol.parameters); end
The analytical solution is:
x=(a-1/p)*cos(pi*s_tilde)+(a-1)/p; y=(a-1/p)*sin(pi*s_tilde); theta=p*a/(a-1)*(s_tilde-1)+pi; s=a*s_tilde;
回答(2 个)
Azzi Abdelmalek
2012-11-17
0 个投票
Star Strider
2012-11-17
0 个投票
I suggest using the deval function. The documentation explains its use, and illustrates a plot as well.
类别
在 帮助中心 和 File Exchange 中查找有关 Boundary Value Problems 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!