I gave the initial condition correctly still the program not working.
조회 수: 3 (최근 30일)
이전 댓글 표시
ti = 0;
tf = 70E-8;
tspan=[ti tf];
k = (0.62).*10^(-5);
% y0= [(10e-6)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
% (10e-6)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
% (10e-6)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
% (10e-6)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
% (10e-6)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
% ((-3.14).*rand(5,1) + (3.14).*rand(5,1))];
y0 = [ 0.00001; 0.00001; 0.00001; 0.00001; 0.00001;
0.00001; 0.00001; 0.00001; 0.00001; 0.00001; 2.5669; 2.0482; 2.0454; -0.7968; 0.2303];
yita_mn = [
0 1 0 0 1;
1 0 1 0 0;
0 1 0 1 0;
0 0 1 0 1;
1 0 0 1 0;
]*(k);
N = 5;
tp = 1E-12;
[T,Y]= ode45(@(t,y) rate_eq(t,y,yita_mn,N),tspan./tp,y0);
figure(1)
plot(T./t,(Y(:,16)),'linewidth',0.8);
hold on
for m = 16:20
plot(T./t,(Y(:,m)),'linewidth',0.8);
end
hold off
grid on
xlabel("time")
ylabel("phase difference")
set(gca,'fontname','times New Roman','fontsize',18,'linewidth',1.8);
function dy = rate_eq(t,y,yita_mn,N,o)
dy = zeros(4*N,1);
dGdt = zeros(N,1);
dAdt = zeros(N,1);
dOdt = zeros(N,1);
P = 0.5;
a = 1;
T = 2E3;
Gt = y(1:3:3*N-2);
At = y(2:3:3*N-1);
Ot = y(3:3:3*N-0);
k = (0.62).*10^(-5);
for i = 1:N
dGdt(i) = (P - Gt(i) - (1 + 2.*Gt(i)).*(At(i))^2)./T ;
dAdt(i) = (Gt(i).*(At(i)));
dOdt(i) = -a.*(Gt(i));
for j = 1:N
dAdt(i) = dAdt(i)+yita_mn(i,j).*(At(j))*sin(Ot(j)-Ot(i));
dOdt(i) = dOdt(i)+yita_mn(i,j).*((At(j)/At(i)))*cos(Ot(j)-Ot(i));
end
end
dy(1:3:3*N-2) = dGdt;
dy(2:3:3*N-1) = dAdt;
dy(3:3:3*N-0) = dOdt;
n1 = (1:5)';
n2 = circshift(n1,-1);
n16 = n1 + 15;
n17 = circshift(n16,-1);
n20 = circshift(n16,1);
j2 = 3*(1:5)-1;
j5 = circshift(j2,-1);
j8 = circshift(j2,-2);
j19 = circshift(j2,1);
dy(n16) = -a.*(Gt(n2)-Gt(n1)) + (k).*(y(j2)./y(j5)).*cos(y(n16)) - (k).*(y( j5)./y(j2)).*cos(y(n16)) + (k).*(y(j8)./y(j5)).*cos(y(n17)) - (k).*(y(j19)./y(j2)).*cos(y(n20));
end
댓글 수: 0
채택된 답변
Walter Roberson
2022년 10월 11일
y0 = [ 0.00001; 0.00001; 0.00001; 0.00001; 0.00001;
0.00001; 0.00001; 0.00001; 0.00001; 0.00001; 2.5669; 2.0482; 2.0454; -0.7968; 0.2303];
That is 15 initial values.
for m = 16:20
plot(T./t,(Y(:,m)),'linewidth',0.8);
end
But you are trying to plot assuming 20 results. The only way to get 20 results is to have 20 or more initial values.
댓글 수: 0
추가 답변 (1개)
Benjamin Thompson
2022년 10월 11일
circshift returns a vector of the same length as its input. So, j2, j5, j8, and j19 are vectors and not scalar values as the line having the failure seems to expect. You can use breakpoints in your script in MATLAB to investigate further and debug the problems.
댓글 수: 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!