using "for loop" to solve 5 different coupled differential equation.
조회 수: 5 (최근 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)
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
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 Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!