I couldn't understand why this program is not working, is my all variable algorithm is correct?
1 次查看(过去 30 天)
显示 更早的评论
clc
ti = 0;
tf = 10E-4;
tspan=[ti tf];
y0=[9;9;1;1;0].*10E-2;
I =0:0.1 :10 ;
Vf = zeros(length(I),1) ;
for i = 1:length(I)
[T,Y]= ode45(@(t,y) rate_eq(y,I(i)),tspan,y0);
Vf(i) = (2.*(((mean(Y(:,1).*Y(:,2).*cos(Y(:,5)))).^2 + (mean(Y(:,1).*Y(:,2).*sin(Y(:,5)))).^2).^0.5))/(mean(Y(:,1).^2)+mean(Y(:,2).^2));
end
disp(Vf)
function dy = rate_eq(y,I)
dy = zeros(5,1);
o = 2E5; %detuning frequency
tc = 30E-9; %photon cavity lifetime
tf = 230E-6; %fluorescence lifetime
a1 = 0.1; %roundtrip loass
a2 = 0.1;
P1 = 0.2; %pumpstrength
P2 = 0.2;
kc = 3E-3; %critical coupling strength
s = 0.17;
k = s.*kc;
%amplitude equation
dy(1) = ((y(3) - a1) * y(1) + k * y(2) * cos(y(5))) ./ tc;
dy(2) = ((y(4) - a2) * y(2) + k * y(1) * cos(y(5))) ./ tc;
%gain medium strength
dy(3) = (P1 - y(3) * (((abs(y(1)))^2 .*I) + 1)) / tf;
dy(4) = (P2 - y(4) * (((abs(y(2)))^2 .*I) + 1)) / tf;
%phase differential equation
dy(5) = o - (k / tc) * (((y(1) ./ y(2)) + (y(2) ./ y(1))) * sin(y(5)));
end
采纳的回答
KSSV
2022-7-12
You need to interchange the variables to the function rate_eq. Try this:
ti = 0;
tf = 10E-4;
tspan=[ti tf];
y0=[9;9;1;1;0].*10E-2;
[T,Y]= ode45(@(t,y) rate_eq(t,y),tspan,y0);
I =0:0.1 :10 ;
Vf = zeros(length(I),1) ;
for i = 1:length(I)
[T,Y]= ode45(@(t,y) rate_eq(I(i),y),tspan,y0);
Vf(i) = (2.*(((mean(Y(:,1).*Y(:,2).*cos(Y(:,5)))).^2 + (mean(Y(:,1).*Y(:,2).*sin(Y(:,5)))).^2).^0.5))/(mean(Y(:,1).^2)+mean(Y(:,2).^2));
end
disp(I)
function dy = rate_eq(I,y)
dy = zeros(5,1);
o = 2E5; %detuning frequency
tc = 30E-9; %photon cavity lifetime
tf = 230E-6; %fluorescence lifetime
a1 = 0.1; %roundtrip loass
a2 = 0.1;
P1 = 0.2; %pumpstrength
P2 = 0.2;
kc = 3E-3; %critical coupling strength
s = 0.17;
k = s.*kc;
%amplitude equation
dy(1) = ((y(3) - a1) * y(1) + k * y(2) * cos(y(5))) ./ tc;
dy(2) = ((y(4) - a2) * y(2) + k * y(1) * cos(y(5))) ./ tc;
%gain medium strength
dy(3) = (P1 - y(3) * (((abs(y(1)))^2 .*I) + 1)) / tf;
dy(4) = (P2 - y(4) * (((abs(y(2)))^2 .*I) + 1)) / tf;
%phase differential equation
dy(5) = o - (k / tc) * (((y(1) ./ y(2)) + (y(2) ./ y(1))) * sin(y(5)));
end
2 个评论
KSSV
2022-7-12
Though you define,dy = zeros(4,1)...you are defining
dy(5) = o - (k / tc) * (((y(1) ./ y(2)) + (y(2) ./ y(1))) * sin(y(5)));
so your dy is 5x1.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!