Тёмный
No video :(

4th-Order Runge-Kutta Method Example 

Prof. Mark Owkes - Montana State University
Подписаться 1,9 тыс.
Просмотров 120 тыс.
50% 1

Example in MATLAB showing how to solve an ODE using the RK4 method.

Опубликовано:

 

28 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 33   
@salimamansoura7838
@salimamansoura7838 3 года назад
May God reward you for all your efforts and all the valuable information that you provide us smoothly .
@Prayat91
@Prayat91 4 года назад
Omg thanks for giving us code to pass some garbage exam
@fatihsevinc8626
@fatihsevinc8626 8 месяцев назад
Masterfully executed!
@muhandez6484
@muhandez6484 Год назад
thanks professor compact and to the point
@shaondas3481
@shaondas3481 3 года назад
Do you have any video on Method of Lines?
@arkansh.h.1313
@arkansh.h.1313 3 года назад
How can I get the code of 4th-Order Runge-Kutta Method for solving integral equations?
@kingtarekdz
@kingtarekdz 5 лет назад
thank you,so simple and usefull
@faguettenicholas7834
@faguettenicholas7834 7 лет назад
Why does it not display the area under the curve from 0 to xfinal?
@somusomesh9159
@somusomesh9159 8 лет назад
what is the alternative function that can be used instead of function handle?
@tahirabatool3931
@tahirabatool3931 7 лет назад
there is only one initial condition as in line 2, but in 12th and 13th line you have used initial conditions x(1)=0 and y(1)=5. why?
@faguettenicholas7834
@faguettenicholas7834 7 лет назад
It's because at x = 0, the function y(x=0) = 5.
@johirulhaque6831
@johirulhaque6831 6 лет назад
Hi sir, i am a under-graduation student there is a code in two file (one is function, another is for output) i am uploading three part one for function , second for output , third for another function where parameter are differents from first one. This code successfully run for first function parameter but not run for third function parameter . please help me. FIRST PART(parameter) function xprime = state1(t,X) % CALCULATE THE TEMPORAL DYNAMICS OF DIFFERENT STATE %__________________________________________________________________ % PARAMETERS USED FOR THE CALCULATION%_____________________________ h = 6.626*10^-34; % Plank's constant (m^2kg/sec) or "Jule" c = 3*10^8; % Speed of light (m/sec^2) lambda_P = 532*10^-9; % wavelength of the pump beam lambda_S = 633*10^-9; % wavelenngth of the signal beam r = 0.5*10^-3; % radius of the pump beam ( 0.5 mm) A = pi*r^2; % Area of the beam E_p = (h*c)/lambda_P; % Pump photon energy (in Jule) E_s = (h*c)/lambda_S; % Signal photon energy (in Jule) %eV = 1.61*10^-19; %E_p_eV = E_p/eV; % Energy of the pump photon in eV %E_s_eV = E_s/eV; % Energy of the laser photon in eV P_p = 1*10^4; % pump power (50 mW) P_s = 32; % signal power (50 mW) sigma_a = (10^-16)*(10^-2)^2; % Absorption cross section (cm^2) sigma_s = (10^-15)*(10^-2)^2; % Emission cross section (cm^2) sigma_TT = (10^-14)*(10^-2)^2; % Triplet-Triplet absorption cross section %sigma_ESA11 = ((10^-16)*(10^-2)^2)/0.001; % Intersystem crossing rate (sec^-1) eta_ISC = 10^8; % Constant intersystem crossing rate sigma_ESA = (10^-14)*(10^-2)^2; %___________________________________________________________ Ip = P_p/(A*E_p); % Pump rate (1/m^2/sce) eta_P = Ip*sigma_a; % Pumping rate (photons/sec) %___________________________________________________________ Is = P_s/(A*E_s); % lasing rate (1/m^2/sce) eta_SE = Is*sigma_s; %___________________________________________________________ t_f = 5*10^-9; % radiative lifetime of the molecules eta_f = 1/t_f; % Rate of spontaneous emission %___________________________________________________________ %eta_ESA = Is*sigma_ESA; %eta_ESA = sigma_ESA; %___________________________________________________________ t_T = 1.5; eta_T = 1/t_T; %______________________________________________ eta_TT = Is*sigma_TT; eta_ESA = Is*sigma_ESA; %______________________________________________________________ %SOLUTION OF ODE BY 4TH ORDER RUNGEE-KUTTA METHOD xprime = [eta_P*X(2)-X(1)*(eta_SE+eta_f+eta_ISC+eta_ESA); -eta_P*X(2)+X(1)*(eta_SE+eta_f)+eta_T*X(3); X(1)*(eta_ISC)-X(3)*(eta_T+eta_TT); eta_TT*X(3); X(1)*eta_ESA]; SECOND PART(ODE Slotuion and plot) S1_0 = 0; S0_0 = 10^32; T1_0 = 0; T2_0 = 0; S2_0 =0; %P_p = 10*10^-3; S_total = S1_0+S0_0+T1_0+T2_0+S2_0; X0 = [S1_0 S0_0 T1_0 T2_0 S2_0]; tspan = [0,100*10^-9]; [t,X] = ode45(@state1,tspan,X0); %plot(t,X) S1 = X(:,1)./S_total; S0 = X(:,2)./S_total; T1 = X(:,3)./S_total; T2 = X(:,4)./S_total; S2 = X(:,5)./S_total; %_______________________________________ %Laser intensity calculation through Population inversion" L = (S1-S0); Norm_L = L/max(L); plot(t,S1,'-r'); hold on plot(t,S0,'-g'); hold on plot(t,T1,'-b'); hold on plot(t,T2,'-*'); hold on plot(t,Norm_L, '--r'); hold on plot(t,S2, '-y') ylim ([0 1]); FIRST PART(For different parameter for which code not run) function xprime = state1(t,X) % CALCULATE THE TEMPORAL DYNAMICS OF DIFFERENT STATE %__________________________________________________________________ % PARAMETERS USED FOR THE CALCULATION%_____________________________ h = 6.626*10^-34; % Plank's constant (m^2kg/sec) or "Jule" c = 3*10^8; % Speed of light (m/sec^2) lambda_P = 556*10^-9; % wavelength of the pump beam lambda_S = 626*10^-9; % wavelenngth of the signal beam r = 0.2*10^-3; % radius of the pump beam ( 0.5 mm) A = pi*r^2; % Area of the beam E_p = (h*c)/lambda_P; % Pump photon energy (in Jule) E_s = (h*c)/lambda_S; % Signal photon energy (in Jule) %eV = 1.61*10^-19; %E_p_eV = E_p/eV; % Energy of the pump photon in eV %E_s_eV = E_s/eV; % Energy of the laser photon in eV P_p = 1*10^4; % pump power (50 mW) P_s = 32; % signal power (50 mW) sigma_a = 1.8*10^-24; % Absorption cross section (cm^2) sigma_s = 9*10^-18; % Emission cross section (cm^2) sigma_TT = .1*10^-12; % Triplet-Triplet absorption cross section %sigma_ESA11 = ((10^-16)*(10^-2)^2)/0.001; % Intersystem crossing rate (sec^-1) eta_ISC = 4.2*10^5; % Constant intersystem crossing rate sigma_ESA = (10^-14)*(10^-2)^2; %___________________________________________________________ Ip = P_p/(A*E_p); % Pump rate (1/m^2/sce) eta_P = Ip*sigma_a; % Pumping rate (photons/sec) %___________________________________________________________ Is = P_s/(A*E_s); % lasing rate (1/m^2/sce) eta_SE = Is*sigma_s; %___________________________________________________________ t_f = 350*10^-12; % radiative lifetime of the molecules eta_f = 1/t_f; % Rate of spontaneous emission %___________________________________________________________ %eta_ESA = Is*sigma_ESA; %eta_ESA = sigma_ESA; %___________________________________________________________ t_T = 10^-3; eta_T = 1/t_T; %______________________________________________ eta_TT = Is*sigma_TT; eta_ESA = Is*sigma_ESA; %______________________________________________________________ %SOLUTION OF ODE BY 4TH ORDER RUNGEE-KUTTA METHOD xprime = [eta_P*X(2)-X(1)*(eta_SE+eta_f+eta_ISC+eta_ESA); -eta_P*X(2)+X(1)*(eta_SE+eta_f)+eta_T*X(3); X(1)*(eta_ISC)-X(3)*(eta_T+eta_TT); eta_TT*X(3); X(1)*eta_ESA]; May be problem occurs in this line [t,X] = ode45(@state1,tspan,X0); How i can solve this.
@christhesoftwareguy5672
@christhesoftwareguy5672 8 лет назад
how can you use this program without using the step size method
@suganyakongan
@suganyakongan 6 лет назад
Hello, I had a problem over here in MATLAB code for solving a linear first ode dx/dt= lambda-sigma*x(t)- c*v(t),dv/dt=k*v(t)-a*z(t),dz/dt=h*x(t)-tow*v(t) with initial conditions x(0)= x0,v(0)=v0,z(0)=x0."Can u help me out sir...
@moumtajimohammedmehdi365
@moumtajimohammedmehdi365 5 лет назад
Thank you Professor
@bilalhaider6309
@bilalhaider6309 6 лет назад
l = 120; %cm s = 80; % cm% R = 2*l/s; %l=connecting rod length % s is stroke d= 6.7 %cm Vd = (pi/4)*(d^2)*s; % d is bore % s is stroke a_1 = (R^2 - (sind(theta))^2)^-0.5; dV= (Vd/2)*sind(theta)*(1+(cosd(theta)*a_1)) Sir, i want to solve above equation dV with respect to theta usuing RK4 method in matlab plz help me
@parvinbedwal7711
@parvinbedwal7711 6 лет назад
can you provide the matlab code for differential quadrature method with RK4 method
@rajanbhandari4828
@rajanbhandari4828 6 лет назад
How can we know the governing function of the plot?
@kotsos70
@kotsos70 7 лет назад
i am trying to use runge kutta on the lorentz force. do you have nay advice?
@spotlessmindset
@spotlessmindset 7 лет назад
I think it will be better to zoom certain areas in your screen it very difficult to see.... but, I like the English, is clear.... just the visual
@pavaattovchhin3938
@pavaattovchhin3938 3 года назад
Can you give this Matlab code?
@anaarcanjo7909
@anaarcanjo7909 5 лет назад
Nice video :)
@asmadidi1384
@asmadidi1384 8 лет назад
i m really confused how to use this method Runge Kutta with Matlab for My code using the analytical methode and Tlm method this my code how i m gonna choose y for this please if you can help to solve it % RC in series TLM application - 2nd edition clear all clc % Vs=input('Source Voltage in Volt ='); Vs=2.7; % R=input('Resistance in ohm ='); R=1; %C=input('Capacitance in Farad ='); C=50; % t=input('Enter The Simulation Time ='); t=300; % dt=input('Time step in second ='); dt= 50; disp('Characteristic Impedance') Zc=dt/(2*C) % k=0 V0c=0; I0=Vs/R; V0ci=-(I0*Zc)/2; V0cr=V0c-V0ci; n=t/dt; for k=1:n Vci(k)=V0cr; I(k)=(Vs-2*Vci(k))/(R+Zc); Vc(k)=2*Vci(k)+I(k)*Zc; Vcr(k)=Vc(k)-Vci(k); V0cr=Vcr(k); % update end %Analytical value of I(t) x=1; for k=0:dt:t i(x)=(Vs/R)*exp(-k/(R*C)); x=x+1; end % Outcomes I=[I0 I]; Vc=[V0c Vc]; Vci=[V0ci Vci]; Vcr=[(V0c-V0ci) Vcr]; t=0:dt:t; plot(t,I),grid,hold,ylabel('magnitude'),xlabel('time in Sec.') plot(t,i,'r') legend('TLM Method','Analytical Method'); % Error Analysis ll=length(i); for k=1:ll err(k)=100*((i(k)-I(k))/i(k)); end disp('Errors in Percent') err;
@hamzafokraoui720
@hamzafokraoui720 8 лет назад
for this function, how we can resolve it : f^4 - f*f^3 + 4*g*g^1
@saeedbamashmos6102
@saeedbamashmos6102 8 лет назад
i need to find a numerical result, what should i have to add?
@prof.markowkes-montanastat3851
+Saeed Bamashmos This question is not very clear. I'm happy to help, but don't understand what you are asking.
@saeedbamshmous36
@saeedbamshmous36 8 лет назад
Thanks sir for responding, my question is can i desply the resalts of y numerically, instade of the graphic method, in the graph we have y in each x as labeled, can i make some changes to the code so that i can have numbers written as followin: For x=1 , y= 0.3 for example. And so on
@prof.markowkes-montanastat3851
+saeed bamshmous Something like for n=1:length(x) disp(['x=',x(n),' y=',y(n)]) end will displace the x and y values. Look at the help for fprintf for other options.
@saeedbamshmous36
@saeedbamshmous36 8 лет назад
Yes Sir. This is exactly what I need, now sir where i should put this order in the code, and when i will find the result printed. I really appreciate your time given to help me sir.
@shahidkhanshahidkhan4032
@shahidkhanshahidkhan4032 4 года назад
with matlab
@pavaattovchhin3938
@pavaattovchhin3938 3 года назад
Can you give this Matlab code?
Далее
2nd-Order ODE
5:19
Просмотров 3 тыс.
Heun's Method Example
7:56
Просмотров 93 тыс.
4th-Order Runge Kutta Method for ODEs
12:07
Просмотров 136 тыс.
AMATH352 Gaussian Elimination Matlab
37:32
Просмотров 32 тыс.
RK4 (Classical 4th-Order Runge-Kutta) Method Examples
39:01
Why Democracy Is Mathematically Impossible
23:34
Просмотров 2 млн
4th Order Runge-Kutta Method-Solve by Hand (example)
13:30