필터 지우기
필터 지우기

Solving First order ODEs simultaneously

조회 수: 1 (최근 30일)
Valerie
Valerie 2023년 9월 28일
댓글: Valerie 2023년 9월 29일
Hello, needed help figuring out why I cannot obtain a solution. I'm sure this is a solvable solution however I keep getting a warning saying no solution is found. Is there any mistake I'm making in the code?
Everything is a constant except E, Sr(t) & Er(t).
% Rigorous Solution Case #1
syms Sr(t) Er(t) E;
E = Ea - Er(t);
Unrecognized function or variable 'Ea'.
ode2a = diff(Sr(t),t) == -(k1*(Ea - Er(t))*Sr(t)) + krev1*Er(t);
ode3a = diff(Er,t) == (k1*(Ea - Er(t))*Sr(t)) - (krev1+k2)*Er(t);
odes = [ode2a; ode3a];
cond1 = Sr(0) == Sa;
cond2 = Er(0) == 0;
conds = [cond1; cond2];
[SrSol(t),ErSol(t)] = dsolve(odes,conds)
  댓글 수: 4
Walter Roberson
Walter Roberson 2023년 9월 28일
Ea = 123; %just to have SOME value
k1 = 42; %just to have SOME value
k2 = 13; %just to have SOME value
krev1 = 48; %just to have SOME value
Sa = 5; %just to have SOME value
% Rigorous Solution Case #1
syms Sr(t) Er(t) E;
E = Ea - Er(t);
ode2a = diff(Sr(t),t) == -(k1*(Ea - Er(t))*Sr(t)) + krev1*Er(t);
ode3a = diff(Er,t) == (k1*(Ea - Er(t))*Sr(t)) - (krev1+k2)*Er(t);
eqns = [ode2a; ode3a];
cond1 = Sr(0) == Sa;
cond2 = Er(0) == 0;
conds = [cond1; cond2];
[eqs,vars] = reduceDifferentialOrder(eqns, [Sr(t), Er(t)])
eqs = 
vars = 
[M,F] = massMatrixForm(eqs,vars)
M = 
F = 
f = M\F
f = 
odefun = odeFunction(f,vars)
odefun = function_handle with value:
@(t,in2)[in2(2,:).*4.8e+1-in2(1,:).*5.166e+3+in2(2,:).*in2(1,:).*4.2e+1;in2(2,:).*-6.1e+1+in2(1,:).*5.166e+3-in2(2,:).*in2(1,:).*4.2e+1]
InitConditions = double(rhs(conds)) %watch out for order though!
InitConditions = 2×1
5 0
[T, Y] = ode45(odefun, [0 0.01], InitConditions);
subplot(2,1,1); plot(T, Y(:,1)); title(string(vars(1)))
subplot(2,1,2); plot(T, Y(:,2)); title(string(vars(2)))
%that almost looks like the initial conditions are reversed.
%what happens if we try reversing the conditions?
[Tr, Yr] = ode45(odefun, [0 0.01], flipud(InitConditions));
figure
subplot(2,1,1); plot(Tr, Yr(:,1)); title(string(vars(1)))
subplot(2,1,2); plot(Tr, Yr(:,2)); title(string(vars(2)))
Valerie
Valerie 2023년 9월 28일
Thank you so much!

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

채택된 답변

Torsten
Torsten 2023년 9월 28일
이동: Torsten 2023년 9월 28일
I'm quite sure there is no analytical solution for your system of ODEs since the right-hand sides are nonlinear in the unknown functions (term Er(t)*Sr(t)).
  댓글 수: 7
Sam Chak
Sam Chak 2023년 9월 28일
Wolfram Mathematica uses DSolve. 😅
Valerie
Valerie 2023년 9월 29일
@Sam Chak I rage quit mathematica this week and is how I eneded up on MATLAB lol but thank you!

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

추가 답변 (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