using runge kutta RK2 on matlab

86 次查看(过去 30 天)
Mohamed Ellabban
Mohamed Ellabban 2022-1-10
编辑: Torsten 2022-1-10
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 个评论
Torsten
Torsten 2022-1-10
Compare your numerical results with the analytical solution
i(t) = V/R*(1-exp(-R/L*t))

请先登录,再进行评论。

回答(1 个)

Torsten
Torsten 2022-1-10
编辑:Torsten 2022-1-10
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

类别

Help CenterFile Exchange 中查找有关 Circuits and Systems 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by