How do I plot this?
Show older comments
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;
Answers (2)
Azzi Abdelmalek
on 17 Nov 2012
0 votes
Star Strider
on 17 Nov 2012
0 votes
I suggest using the deval function. The documentation explains its use, and illustrates a plot as well.
Categories
Find more on Boundary Value Problems in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!