Solving the differential equation by the Runge-Kutta method (ode45)
4 ビュー (過去 30 日間)
古いコメントを表示
I want solve this equation numerically and use fourth order Runge-Kutta method. (ode45)
What is the code?
My code:
function dfdt = odefun2(x,y)
dfdt = [y(2); y(1) .^(-3) - (w .*r0 ./c) .^2 .*phi2 .*y(1)];
end
****
clc, clear, close all;
w = 2e16;
r0 = 30e-6;
c = 3e8;
p = 2.5;
f = 1;
Wp0 = p .*c ./r0;
a02 = 0.050;
phi2 = (Wp0 ./w) .^2 .*(3 .*a02 ./f .^4) ./4 ./(1 + a02 ./2 ./f .^2) .^1.5...
.*(1 + (56 + a02 ./f .^2) ./3 ./(1 + a02 ./2 ./f .^2) ./p .^2 ./f .^2);
[t, y] = ode45(@odefun2,[0 3],[1,0]);
******
But it gives an error ..
I have attached two pictures to the question, look at them if you need.
採用された回答
Torsten
2024 年 3 月 6 日
編集済み: Torsten
2024 年 3 月 6 日
[t, y] = ode45(@odefun2,[0 3],[1,0]);
plot(t,y(:,1))
function dfdt = odefun2(x,y)
w = 2e16;
r0 = 30e-6;
c = 3e8;
p = 2.5;
Wp0 = p .*c ./r0;
a02 = 0.050;
phi2 = (Wp0/w)^2 * 3*a02/y(1)^4 / (4*(1+a02/(2*y(1)^2))^1.5) *...
(1 + 1/(p^2*y(1)^2) * (56+a02/y(1)^2)/(3*(1+a02/(2*y(1)^2))^0.5));
dfdt = [y(2); y(1) .^(-3) - (w .*r0 ./c) .^2 .*phi2 .*y(1)];
end
5 件のコメント
Torsten
2024 年 3 月 6 日
編集済み: Torsten
2024 年 3 月 6 日
syms f(x) p c r0 a02 w
Wp0 = p*c/r0;
e = 1 - (Wp0/w)^2 / sqrt(1+a02/(2*f^2)) * (1- 1/p^2 * 3*a02/f^4 / sqrt(1+a02/(2*f^2)));
simplify(diff(e,x))
and df/dx in your code is y(2).
[t, y] = ode45(@odefun2,[0 3],[1,0]);
plot(t,y(:,1))
function dfdt = odefun2(x,y)
w = 2e16;
r0 = 30e-6;
c = 3e8;
p = 2.5;
Wp0 = p .*c ./r0;
a02 = 0.050;
phi2 = (Wp0/w)^2 * 3*a02/y(1)^4 / (4*(1+a02/(2*y(1)^2))^1.5) *...
(1 + 1/(p^2*y(1)^2) * (56+a02/y(1)^2)/(3*(1+a02/(2*y(1)^2))^0.5));
e = 1 - (Wp0/w)^2 / sqrt(1+a02/(2*y(1)^2)) * (1- 1/p^2 * 3*a02/y(1)^4 / sqrt(1+a02/(2*y(1)^2)));
sigma1 = a02/(2*y(1)^2) + 1;
dedx = 3*a02^2*c^2*y(2)/(r0^2*w^2*y(1)^7*sigma1^2) ...
-12*a02*c^2*y(2)/(r0^2*w^2*y(1)^5*sigma1)...
-a02*c^2*p^2*y(2)/(2*r0^2*w^2*y(1)^3*sigma1^1.5);
dfdt = [y(2); y(1)^(-3)-1/(2*e)*dedx*y(2)-(w*r0/c)^2*phi2*y(1)];
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numerical Integration and Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!