How to give a final value to solve an ODE's, instead of the standard initial values?

44 ビュー (過去 30 日間)
Kenny
Kenny 2013 年 2 月 25 日
コメント済み: SATISH luke 2021 年 2 月 25 日
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 件のコメント
SATISH luke
SATISH luke 2021 年 2 月 25 日
what if one variable known at the start and other at the end of time

サインインしてコメントする。

採用された回答

Jan
Jan 2013 年 3 月 14 日
編集済み: Jan 2013 年 3 月 14 日
When you transform x -> c - x, the derivative d/dx needs a change in the sign also.
The easiest way to integrate from the end to the initial time is to revert tspan:
tspan = [x_end, 0];
Then Matlab's ODE integrators handle the sign properly automagically.

その他の回答 (2 件)

Juan Camilo Medina
Juan Camilo Medina 2013 年 3 月 13 日
There are different methods to solve a boundary value problem, which is effectively what you have. The easiest one is the shooting method:

Sana Ben Hmouda
Sana Ben Hmouda 2018 年 7 月 9 日
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

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by