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!