Applying updated initial conditions at every points of tspan and solve system of ODE using ode45

2 ビュー (過去 30 日間)
AkB
AkB 2023 年 3 月 24 日
コメント済み: Torsten 2023 年 3 月 25 日
I am solving 6 ODEs (3 are of 2nd order and 3 are of 1st order) simultaneously. I need my code to be such that the initial condition is applied at each points of tspan (say, tspan=t0, t1, t2, t3.....tn) instead of only at t=t0. Moreover, initial conditions at each points of tspan need to be updated based of results of ODEs at the previous time step.
Mathematically, my eqns are (in much simplified manner):
d2xdt2= u1+vp*p1 ;
d2ydt2= u2+vp*p2 ;
d2zdt2= u3+vp*p3 ;
dp1dt= a1*p1+a2*p2+a3*p3 ;
dp2dt= b1*p1+b2*p2+b3*p3 ;
dp3dt= c1*p1+c2*p2+c3*p3 ;
Here, a1, a2, a3, b1, b2 b3, c1, c2, c3 and vp are constants, and u1, u2, and u3 are some functions of (x, y, z, t).
Initial condition: y0_a=[0 v1_ini 0 v2_ini 0 v3_ini_3 p1_0 p2_0 p3_0]
Now, with this I am getting a result wherein the value of v1=dxdt is v1=v1_ini at t=t0, however, for t > t0, v1 drops (please refer image attached).
I want : y0_a to be updated at each points of tspan=(t0, t1, t2, t3.....tn) according to
v1_ini (ti) = u0x + vp * p1(ti)
v1_ini (ti+1) = u0x + vp * p1(ti+1)....and so on. [u0x is a constant.]
Basically, I am simulating a microswimmer and it's velocity never drops down and it's velocity depends on instantaneous values of p=(p1, p2, p3). I have tried creating a for loop to update the initial value, but it repeats same value. Please see the attached code.

回答 (1 件)

Torsten
Torsten 2023 年 3 月 24 日
Then why do you solve for v1 if you want to prescribe it ? Simply set
v1 = u0x + vp*p1
in your code and determine displacement via
dx/dt = v1
  2 件のコメント
Torsten
Torsten 2023 年 3 月 25 日
Instead I need to get a solution that where initial conditions at each time step is u0x+vp*p1(t), where p1(t) will be calculated simultaneously from ODEs involving dpdt.
This is the same as if you prescribe v1 = u0x + vp*p1 in my opinion. Or do you see any difference ?
Torsten
Torsten 2023 年 3 月 25 日
Giving initial values at each step by an explicit formula means: prescribing the variable. And if you prescribe an initial value for v of v = uf(0)+vp*p or v = uf(t)+vp*p means: you set the variable v to uf(0)+vp*p resp. uf(t)+vp*p.

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

カテゴリ

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