ode45 with a array of vector

조회 수: 1 (최근 30일)
AkB
AkB 2023년 3월 23일
댓글: AkB 2023년 3월 27일
I am solving 6 ODEs simultaneously. My eqns are:
eq1 = diff(x,t) == u1+vp.*p1 ;
eq2 = diff(y,t) == u2+vp.*p2 ;
eq3 = diff(z,t) == u3+vp.*p3 ;
eq1 = diff(p1,t) == a1*p1+a2*p2+a3*p3 ;
eq2 = diff(p2,t) == b1*p1+b2*p2+b3*p3 ;
eq3 = diff(p3,t) == c1*p1+c2*p2+c3*p3 ;
Here, a1, a2, a3, b1, b2 b3, c1, c2, c3 and vp are constants.
u1, u2, and u3 are vector of dimension [1 X 100]. Each values of u1, u2, and u3 corresponds to time points in tValues = linspace(0,10,100). I want to compute p1, p2, p3 and x, y, z for tValues = linspace(0,10,100).
My code is following: ;
vars = [x(t); z(t); y(t); p1(t); p2(t); p3(t)];
V = odeToVectorField([eq2 eq1 eq3 eq4 eq5 eq6]);
M = matlabFunction(V,'vars', {'t','Y'});
y0=[0 0 0 p1_0 p2_0 p3_0];
ySol_a = ode45(M,interval,y0);
Once the code is run, it shows following error message:
MuPAD error: Error: Cannot convert the initial value problem to an equivalent dynamical system. Either the differential equations cannot be solved for the highest derivatives or inappropriate initial conditions were specified. [numeric::ode2vectorfield]

채택된 답변

Torsten
Torsten 2023년 3월 23일
a1 = ...;
a2 = ...;
a3 = ...;
b1 = ...;
b2 = ...;
b3 = ...;
c1 = ...;
c2 = ...;
c3 = ...;
vp = ...;
tValues = linspace(0,10,100);
u1Values = ...;
u2Values = ...;
u3Values = ...;
u1fun = @(t)interp1(tValues,u1Values,t);
u2fun = @(t)interp1(tValues,u2Values,t);
u3fun = @(t)interp1(tValues,u3Values,t);
fun = @(t,y)[u1fun(t)+vp*y(4);u2fun(t)+vp*y(5);u3fun(t)+vp*y(6);a1*y(4)+a2*y(5)+a3*y(6);b1*y(4)+b2*y(5)+b3*y(6);c1*y(4)+c2*y(5)+c3*y(6)];
tspan = tValues;
p1_0 = ...;
p2_0 = ...;
p3_0 = ...;
y0 = [0 0 0 p1_0 p2_0 p3_0];
[T,Y] = ode45(fun,tspan,y0);
plot(T,Y)
  댓글 수: 6
Torsten
Torsten 2023년 3월 25일
How do I provide this dynamic initial condition?
I think I answered this already. An initial condition is not dynamic.
If you want to set
v1(t) = constant1 + vp*p1,
v2(t) = constant2 + vp*p2,
v3(t) = constant3 + vp*p3
your equations to integrate become
diff(x,t) = constant1 + vp*p1
diff(y,t) = constant2 + vp*p2
diff(z,t) = constant3 + vp*p3
diff(p1,t) == JTx_1+JTx_2+JTx_3;
diff(p2,t) == JTy_1+JTy_2+JTy_3;
diff(p3,t) == JTz_1+JTz_2+JTz_3;
AkB
AkB 2023년 3월 27일
Thanks, it works.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by