How to give a final value to solve an ODE's, instead of the standard initial values?
33 views (last 30 days)
Show older comments
I'm solving a first order differential equation with variable constants and a mass matrix. Therefore, I use ODE113. As shown in the code below, I call 2 functions for defining the ODE and the mass matrix. In order to give in the final value as 'initial condition', in the first call of ode113, the independent variable x is transformed to x_end - x. For comparison, in the second call of ode113, the original x is used with the initial value given from the previous solution. The functions called in the second time are identical as in the first time, except that now x is immediately defined by the function input, and has no transformation. Both solutions were plotted but do not coincide. Why is this, is this the correct way of transforming the pre-programmed initial value programs to final value problems?
Thanks in advance! regards, Kenny
% Limit of the differential eq.:
x_end=2.5;
%
% Parameters:
x0=[0.32;0.15;45];
%
% Final condition is known:
options =odeset('Mass',@(xb) Mass_fromback(x0(1),x0(2),xb,x_end),'MStateDependence','none','RelTol',1e-3);
yfb=ode113(@(xb,y)diffEqn_fromback(x0(1),x0(2),x0(3),xb,y,x_end),[0 x_end], 0,options);
%
% Initial condition from previous solution:
y0=deval(yfb,x_end);
% Solve by giving in initial condition:
options =odeset('Mass',@(xb) Mass(x0(1),x0(2),xb),'MStateDependence','none','RelTol',1e-3);
y=ode113(@(xb,y)diffEqn(x0(1),x0(2),x0(3),xb,y),[0 x_end], y0,options);
with functions:
function M=Mass_fromback(E,nu,xb,x_end)
% Define variable from back to the front, as such, the initial condition
% will be the deformation at the back of the chamber.
x=x_end-xb;
%
hx=1.2-x*tan(3*pi/180);
bx=0.9-x*(2*tan(3*pi/180));
A=-E.*(1-nu);
%
M=A.*hx.*bx;
and
function Mdydx=diffEqn_fromback(E,nu,mu,xb,y,x_end)
%
% Define variable from back to the front:
x=x_end-xb;
%
B=E*nu*(mu+(mu+tan(3*pi/180))./(1-mu*3*pi/180));
D= E*(mu +(mu+8*pi/180)/(1-mu*3*pi/180));
%
Mdydx= B.*x.*y +(1-nu).*D.*x.*log(x+0.1);
For comparison, the two solutions are plotted but they do not coincide:
figure;
plot(x_end-yfb.x,yfb.y,y.x,y.y)
xlabel('x'),ylabel('y'), legend('solved with xb = x\_end - x','solved with x')
1 Comment
Accepted Answer
More Answers (2)
Juan Camilo Medina
on 13 Mar 2013
There are different methods to solve a boundary value problem, which is effectively what you have. The easiest one is the shooting method:
0 Comments
Sana Ben Hmouda
on 9 Jul 2018
Hello, i have the same problem but i can't get the suggested solutions. Would any one provide me plz with a solution to my problem? In fact i'm solving dxdt=(A+BK)x by means of ode45, the solution x(t) converges to zero, now i would like to set the final value of the solution according to a desired value of xd, someone suggected that i replace dxdt=(A+Bk)x+xd, but the result still converges to zero. Thanks
0 Comments
See Also
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!