using runge kutta RK2 on matlab

95 views (last 30 days)
Mohamed Ellabban
Mohamed Ellabban on 10 Jan 2022
Edited: Torsten on 10 Jan 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 Comments
Torsten
Torsten on 10 Jan 2022
Compare your numerical results with the analytical solution
i(t) = V/R*(1-exp(-R/L*t))

Sign in to comment.

Answers (1)

Torsten
Torsten on 10 Jan 2022
Edited: Torsten on 10 Jan 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

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!