using "for loop" to solve 5 different coupled differential equation.
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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)
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.
1 Commento
Torsten
il 2 Ago 2022
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!