Help with ODEs in bvp4c
Show older comments
Hello! I am trying to solve a 2nd order ODE with bvp4c. The differential equation is like: a(x)+b(x)*d/dx(g(x)*dy/dx)=c(x),where: a(x),b(x),c(x) are constant piecewise functions g(x) is a piecewise function but not constant (g(x)=a*x+b) The bc are y(0)=0 and y(10)=0. I created 2 first order ODEs : 1)R=g(x)*dy/dx 2)a(x)+b(x)*dR/dx=c(x) but it did not work, maybe because of the nature of the boundary conditions. Any ideas or suggestions on how to handle this problem?Thanks.
function bvp4
xlow=0;
xhigh=0.30;
solinit=bvpinit(linspace(xlow,xhigh,1000),[0 0]);
sol = bvp4c(@bvp4ode,@bvp4bc,solinit);
xint=linspace(xlow,xhigh);
Sxint=deval(sol,xint);
Sxint1=sqrt(Sxint);
xint=linspace(xlow,xhigh);
plot(xint,Sxint1(1,:),'r')
function dydx = bvp4ode(x,y)
So=0.00125;
dydx = [y(2)/(H(x)*H(x)); (G(x)+1*f(x)*y(1)-1000*9.81*So*H(x))/(1000*0.5*l(x)*(f(x)/8)^0.5)];
function res = bvp4bc(ya,yb)
res = [ya(1); yb(1)];
function fval = f(x)
first=0.08;
second=0.17;
third=0.3;
if (x >= 0) && (x <= first)
fval =0.0187;
elseif (x > first) && (x <= second)
fval = 0.0298;
elseif (x > second) && (x <= third)
fval = 0.0408;
end
function Gval = G(x)
first=0.08;
second=0.17;
third=0.3;
if (x >= 0) && (x <= first)
Gval = 0.2502;
elseif (x > first) && (x <= second)
Gval = 0.2502;
elseif (x > second) && (x <= third)
Gval = -0.2330;
end
function Hval = H(x)
first=0.08;
second=0.17;
third=0.3;
if (x >= 0) && (x <= first)
Hval = 0.136;
elseif (x > first) && (x <= second)
Hval = -(2/3)*x+(71/375);
elseif (x > second) && (x <= third)
Hval = 0.076;
end
function lval = l(x)
first=0.08;
second=0.17;
third=0.3;
if (x >= 0) && (x <= first)
lval = 0.067;
elseif (x > first) && (x <= second)
lval = 0.134;
elseif (x > second) && (x <= third)
lval = 0.172;
end
Answers (2)
Torsten
on 4 May 2016
0 votes
What do you mean by "it did not work" ?
Best wishes
Torsten.
Jan
on 4 May 2016
0 votes
Your problem is not differentiable due to the if statements in the function to be integrated. A boundary value solver calculates the derivative of the local solution to determine the search direction. But if the problem does not have a well defined derivative, you can expect the solver to fail.
Perhaps a multiple shooting approach helps to control this problem, because it reduces teh danger of exploding trajectories caused by discontinuities. If the positions of the multiple shooting nodes are set at the discontinuities, the problem even vanishes and the soltuion will be mathematically well defined.
Categories
Find more on Ordinary Differential Equations 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!