フィルターのクリア

solving the equation using rk-4 method, but couldn't get the right output, last time I forget to add the program please check this one.

1 回表示 (過去 30 日間)
i want to solve this, where σ = 0.1, L0 = 0.5, k= 0.01, tc = 70E-9
format long
a = 0;
b = 4;
h = 0.1;
k = 0.01; % critical coupling strength
L = 0.5;
s = 0.1;
tc = 70E-9; % photon life time in cavity
n = (b-a)/h ;
t = a + (0:n)*h;
func1 = @(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))];
for i = 1:n
k1 = func1(y(i));
k2 = feval(func1, y(i)+(k1/2)*h);
k3 = feval(func1, y(i)+(k2/2)*h);
k4 = feval(func1, y(i)+(k3*h));
y(i+1) = y(i) + (h/6)*(k1+(2*(k2+k3))+k4);
end
plot(t,y)
  7 件のコメント
Walter Roberson
Walter Roberson 2022 年 7 月 21 日
You should preallocate y as length n+1. With your current code if you just happen to have a longer y in your workspace you would have a problem.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by