How can I solve the coupled differential equation with variable coefficients?

조회 수: 3 (최근 30일)
I try to solve coupled differential equation in matlab. This is the code I was typed in matlab
syms u(t) v(t)
ode1 = diff(u) == v;
ode2 = diff(v) == ((5/sqrt(2))*exp((1-sqrt(2))*t)-(5/sqrt(2))*exp((1+sqrt(2))*t)+1)*u + (((5*(1-sqrt(2)))/sqrt(2))*exp((1-sqrt(2))*t)-((5*(1+sqrt(2)))/sqrt(2))*exp((1+sqrt(2))*t)+2)*v;
odes = [ode1; ode2]
cond1 = u(0) == 1;
cond2 = v(0) == 0;
conds = [cond1; cond2];
[uSol(t), vSol(t)] = dsolve(odes,conds)
In command window
Warning: Unable to find explicit solution.
> In dsolve (line 190)
In coupled (line 8)
Error using sym/subsindex (line 855)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
Error in coupled (line 8)
[uSol(t), vSol(t)] = dsolve(odes,conds)
Can someone help me with this error? Thank you.
  댓글 수: 5
Vellapandi M Research Scholar
Vellapandi M Research Scholar 2020년 1월 9일
Thank you once again. I need solution in terms of t. But I get this.
Warning: Unable to find explicit solution.
> In dsolve (line 190)
In coupled (line 8)
uSol =
[ empty sym ]
vSol =
[ ]
David Goodmanson
David Goodmanson 2020년 1월 9일
that's right. Matlab can't solve it symbolically, but there is always numerically..

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

채택된 답변

Dinesh Yadav
Dinesh Yadav 2020년 1월 22일
Hi Vellapandi,
Continuing from David Goodmanson's comment you can solve it numerically. Below is the code for it.
tspan = [0 5];
y0=[1;0];
[uSol, vSol] = ode45(@(t,x) [x(1);((5/sqrt(2))*exp((1-sqrt(2))*t)-(5/sqrt(2))*exp((1+sqrt(2))*t)+1)*x(2) + (((5*(1-sqrt(2)))/sqrt(2))*exp((1-sqrt(2))*t)-((5*(1+sqrt(2)))/sqrt(2))*exp((1+sqrt(2))*t)+2)*x(1)],tspan,y0)
You can change the time limits as per your application.
You can refer to documentation link below to see how to solve system of differential equations.
Hope it helps.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by