Solving the differential equation by the Runge-Kutta method (ode45)

4 views (last 30 days)
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.
  5 Comments
Torsten
Torsten on 6 Mar 2024
Edited: Torsten on 6 Mar 2024
According to your code, your boundary conditions are
f(zeta=0) = 1
df/dzeta (zeta=0) = 0
Is this correct ?
Did you differentiate depsilon/dzeta somewhere to insert it into the differential equation ? I cannot find it in your code.
Babr
Babr on 6 Mar 2024
Yes, the boundary conditions you said are correct.
The second term in right hand of equation has been usually overlooked in most of the studies in view of negligible impact.

Sign in to comment.

Accepted Answer

Torsten
Torsten on 6 Mar 2024
Edited: Torsten on 6 Mar 2024
[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 Comments
Torsten
Torsten on 6 Mar 2024
Edited: Torsten on 6 Mar 2024
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))
ans(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

Sign in to comment.

More Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!