solving a differential equation using ode45 but the problem is i didn't get what i expected.

조회 수: 1 (최근 30일)
i want to solve this, where σ = 0.1, L0 = 0.5, k= 0.01, tc = 70E-9
and U(Φ0) is
so that the phase difference Φ0 vs t graph and potential graph U(Φ0) vs Φ0 look like this
I m getting this
for Φ0 vs t my program is
=================================================================
ti = 0; % inital time
tf = 10E-5; % final time
tspan = [ti tf];
o =10E5;
k = 0.01; % critical coupling strength
L = 0.5;
s = 0.1;
tc = 70E-9; % photon life time in cavity
f = @(t,y) [(-(s^2)*k/tc)*sin(y - pi/2) + L*(s^2)/(2*tc)*sin(y + pi/2)/sqrt(1 + cos(y + pi/2))];
[T, Y] = ode45(f,tspan, 0);
Y = linspace(-3,3,length(Y));
U = zeros(length(Y),1) ;
for i = 1:length(Y)
U(i) = -(1E-6).*(Y(i)) - (2 + (0.1)^2 ).*((0.033)./(70E-9)).*cos(Y(i) - pi/2) + (0.5).*(((0.1)^2)./(70E-9)).*((1 + cos(Y(i) + pi/2))^(0.5));
end
plot(Y,U);
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
xlabel('\phi')
ylabel('U')
=======================================================================
for U( Φ0) vs Φ0
==========================================================================
ti = 0; % inital time
tf = 10E-5; % final time
tspan = [ti tf];
o =10E5;
k = 0.01; % critical coupling strength
L = 0.5;
s = 0.1;
tc = 70E-9; % photon life time in cavity
f = @(t,y) [(-(s^2)*k/tc)*sin(y - pi/2) + L*(s^2)/(2*tc)*sin(y + pi/2)/sqrt(1 + cos(y + pi/2))];
[T, Y] = ode45(f,tspan, 0);
Y = linspace(-3,3,length(Y));
U = zeros(length(Y),1) ;
for i = 1:length(Y)
U(i) = -(1E6).*(Y(i)) - (2 + (0.1)^2 ).*((0.033)./(70E-9)).*cos(Y(i) - pi/2) + (0.5).*(((0.1)^2)./(70E-9)).*((1 + cos(Y(i) + pi/2))^(0.5));
end
plot(Y,U);
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
xlabel('\phi')
ylabel('U')
====================================================================================
please tell me what's wrong in this program and what parameter can make my result correct?

채택된 답변

Sam Chak
Sam Chak 2022년 7월 20일
Nothing wrong with code. The ode45 produces the solution based your given equation and input parameters.
However, one thing is obvious though. This initial value is non-zero.
f = @(t,y) [(-(s^2)*k/tc)*sin(y - pi/2) + L*(s^2)/(2*tc)*sin(y + pi/2)/sqrt(1 + cos(y + pi/2))];
[T, Y] = ode45(f,tspan, 0);
subplot(211)
plot(T, Y), xlabel('t'), ylabel('\sigma')
phase = linspace(-pi, pi, 3601);
U = - (1E-6)*phase - (2 + 0.1^2)*((0.033)/(70E-9))*cos(phase - pi/2) + 0.5*((0.1^2)/(70E-9))*sqrt(1 + cos(phase + pi/2));
subplot(212)
plot(phase, U), xlabel('\sigma'), ylabel('U')
  댓글 수: 16
SAHIL SAHOO
SAHIL SAHOO 2022년 7월 20일
if i don't want to use the Φ0 i obtained from the ODe45 to get U then i have to use for loop right?
Torsten
Torsten 2022년 7월 20일
편집: Torsten 2022년 7월 20일
No.
Z = linspace(-3,3,size(Y,1));
U = -1E6*Z - (2 + 0.1^2 )*0.033/70E-9*cos(Z - pi/2) + 0.5*0.1^2/70E-9*(1 + cos(Z + pi/2)).^0.5;
plot(Z,U)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by