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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by