using "for loop" to solve 5 different coupled differential equation.
6 views (last 30 days)
Show older comments
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 Comment
Torsten
on 2 Aug 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.
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!