How to design ode with multicoupled system?

Hallo guys i wanna design a ode 45 system with multicoupled equations like in the image.
It its used to any input N and initial values. And my code doesnt work with those loops in N=1 but theres no error. So could someone help me to improve it? Thank you!
Here is my code:
%%coeff def
GAMMA_m=0.1;
gamma_m=1;
k_m=5234;
T_1_inv=0.33;
g_m2=5*10^-12;
w_1=4*pi;
d_0=6*10^15;
N=1;
%%initialisierung
y0 = [1.38*10^15; 10^11; 0 ];
%y0(3*N,1) = 0;
tspan = [0 60];
[t,y] = ode45(@(t,y) ODEsystem(t,y,GAMMA_m,gamma_m,k_m,T_1_inv,g_m2,w_1,d_0,N),tspan,y0);
%%plot
subplot(2,2,1)
plot(t,y(:,1),'-o')
title('Subplot 1: d_m')
subplot(2,2,2)
plot(t,y(:,2),'-o')
title('Subplot 1: A')
subplot(2,2,3)
plot(t,y(:,3),'-o')
title('Subplot 1: Fi')
subplot(2,2,4)
alpha = y(2).*exp(1i.*y(3));
plot(t,alpha,'-o')
title('Subplot 4: alpha')
%%funtion
function dydt = ODEsystem(t,y,gamma_m,r_m,k_m,T_1_inv,g_m2,w_1,d_0,N)
dydt = zeros(3*N,1);
for u = 1:N
dydt(3*u-2) = gamma_m*(d_0-y(3*u-2))- y(3*u-2)*T_1_inv- sumterm1(y);
[T2,T3]=sumterm2(y);
dydt(3*u-1) = -r_m*y(3*u-1) + T2(u);
dydt(3*u) = w_1 + T3(u);
end
function T1 = sumterm1(y)
T1 = 0;
for m = 2 :3: 3*N % A_v, v = 1,2,3...
for n =2 :3 :3*N % A_sigma,sigma = 1,2,3...
T1 = T1 + 4*g_m2/k_m*y(m)*y(n)*cos(y(m+1)-y(n+1));
end
end
end
function [T2,T3] = sumterm2(y)
T=zeros(N,2);
T2= T(:,1);
T3= T(:,2);
for o = 3:3:3*N % tao = 1,2,3...
T(u,1) = T(u,1) + g_m2/k_m*y(3*u-2)*y(o-1)*cos(y(o)-y(3*u));
T(u,2) = T(u,2) + g_m2/k_m*y(3*u-2)/y(3*u-1)*y(o-1)*sin(y(o)-y(3*u));
end
end
end

2 Comments

What is the relation between the posted code and your question? Is there a problem within the code?
Ah yes.....My code doesnt work as I wished because the outplot looks total different from the one when i only focus on the N=0 without loops. So I guess it must has some troubles with the loop i use. I dont know i uploaded my description and a image and seems it doesnt show up..

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 17 Feb 2022

Edited:

on 18 Feb 2022

Community Treasure Hunt

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

Start Hunting!