using "for loop" to solve 5 different coupled differential equation.

3 次查看(过去 30 天)
syms A(t) O(t)
a = 0.6;
n = 0.05;
tc = 10E-9;
r = 1.5;
F = 1;
N = 5;
for i = 1:N
ode1 = diff(A(i)) == (-1/(2*tc)).*(1 - r/(1+ (A(i)^2)./F)).*A(i) + (n/(2*tc)).*((cos(O(i))).*A(i+1) + (cos(O(i-1))).*A(i-1)) ;
ode2 = diff(O(i)) == (a./(2*tc)).*( r/(1 + (A(i+1)^2)./F) - r/(1 + (A(i)^2)./F) ) + (n/(2*tc)).*(((A(i+2)./A(i+1)).*sin(O(i+1))) - (A(i+1)./A(i) + A(i)./A(i+1) ).*sin(O(i)) + (A(i-1)./A(i)).*sin(O(i-1)));
odes = [ode1(i); ode2(i)]
S(i) = dsolve(odes(i))
A(i)Sol(t) = S.A(i)
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
O(i)Sol(t) = S.O(i)
[A(i)Sol(t),O(i)Sol(t)] = dsolve(odes(i))
conds = [1; 0];
[A(i)Sol(t),O(i)Sol(t)] = dsolve(odes(i),conds)
fplot(A(i)Sol)
hold on
fplot(O(i)Sol)
grid on
end
I want to use for loop so it will solve 5 couple differential equation,
first it will take i =1 to solve A(1) and O(1) and then i want to plot A(1) vs time. i want to do this till A(5).
and i want to put a condition in which is like if i >=5 then the i+1 becomes 1 and i+2 becomes 2.
odes = 
Error using mupadengine/feval_internal
No differential equations found. Specify differential equations by using symbolic functions.

Error in dsolve>mupadDsolve (line 334)
T = feval_internal(symengine,'symobj::dsolve',sys,x,options);

Error in dsolve (line 203)
sol = mupadDsolve(args, options);
  1 个评论
Torsten
Torsten 2022-8-2
Your equations cannot be solved using "dsolve" because they are far too compliciated.
Either use Walter's suggestion to prepare the function used for ODE45 by MATLAB's "odefunction"
or define your function to be used for ODE45 directly.

请先登录,再进行评论。

回答(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