ode 45 and for loop

12 ビュー (過去 30 日間)
Tuur Vanderhaegen
Tuur Vanderhaegen 2020 年 11 月 23 日
コメント済み: Tuur Vanderhaegen 2020 年 11 月 23 日
Hi,
I would like to use a for loop for a constant value i in my diff.eq. but I don't know how to implement it. Also I would like to have the matrices X and T for al the values of i.
for i : 0.1:0.1:10
[T,X] = ode45(@fx, [0 4], [0 0]) %Can I implement i here and give the matrices X and T an index?
end
function dx = fx(t,x) % Can I give i as an input here.
rho = 1.225;
C_w = 0.3;
A = 0.005;
m = 0.314;
C_r = 0.035;
R_T = 0.7;
n_0 = 378.33;
i = 1;
T_stall = 0.1868;
r = 0.030;
dx = zeros (2,1);
dx(1) = x(2);
dx(2) = (-T_stall * R_T * i^2 * ((1000 * x(2)/ pi ) - n_0/i)/(n_0 * r) - m * 9.81 * C_r - 0.5 * rho * A * C_w * x(2)^2)/m;
% the diff. eq. with i
end

採用された回答

Stephan
Stephan 2020 年 11 月 23 日
k = 0;
T_sol = cell(1,100);
X_sol = cell(1,100);
for ii = 0.1:0.1:10
k = k+1;
[T,X] = ode45(@(t,x)fx(t,x,ii), [0 4], [0 0]);
T_sol{k} = T;
X_sol{k} = X;
end
% plot first and last solution
plot(T_sol{1}, X_sol{1})
hold on
plot(T_sol{100}, X_sol{100})
hold off
function dx = fx(~,x,ii) % Can I give i as an input here.
rho = 1.225;
C_w = 0.3;
A = 0.005;
m = 0.314;
C_r = 0.035;
R_T = 0.7;
n_0 = 378.33;
T_stall = 0.1868;
r = 0.030;
dx = zeros (2,1);
dx(1) = x(2);
dx(2) = (-T_stall * R_T * ii.^2 * ((1000 * x(2)/ pi ) - n_0/ii)/(n_0 * r) - m * 9.81 * C_r - 0.5 * rho * A * C_w * x(2)^2)/m;
% the diff. eq. with i
end
  1 件のコメント
Tuur Vanderhaegen
Tuur Vanderhaegen 2020 年 11 月 23 日
Thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by