using runge kutta RK2 on matlab

91 visualizaciones (últimos 30 días)
Mohamed Ellabban
Mohamed Ellabban el 10 de En. de 2022
Editada: Torsten el 10 de En. de 2022
Task: You have to use this method to solve the following IVP:
An RL circuit has an emf of 5 V, a resistance of 50 Ω, an inductance of 1 H, and no initial
current ( i.e i(1)=0). Find the current in the circuit at any time t.
The formula is:
Ri+L(di/dt)=V
  5 comentarios
Mohamed Ellabban
Mohamed Ellabban el 10 de En. de 2022
Torsten
Torsten el 10 de En. de 2022
Compare your numerical results with the analytical solution
i(t) = V/R*(1-exp(-R/L*t))

Iniciar sesión para comentar.

Respuestas (1)

Torsten
Torsten el 10 de En. de 2022
Editada: Torsten el 10 de En. de 2022
function main
f = @(x,y) 5-50*y;
a = 0;
b = 1;
n = 100;
h = (b-a)/n;
y(1) = 0;
i = 0;
for x= a:h:b-h
i = i+1;
k1 = f(x,y(i));
k2 = f(x+h,y(i)+h*k1);
phi = 0.5*k1 + 0.5*k2;
y(i+1)= y(i)+ h*phi;
end
x = a:h:b;
V = 5;
R = 50;
L = 1;
y_ana = V/R*(1-exp(-R/L*x));
plot(x,[y;y_ana])
end

Categorías

Más información sobre Circuits and Systems en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by