using runge kutta RK2 on matlab

89 ビュー (過去 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 件のコメント
Mohamed Ellabban
Mohamed Ellabban 2022 年 1 月 10 日
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 Center および File ExchangeCircuits and Systems についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by