MATLAB Answers

## ODE solver problem with input

Asked by Sebastian Marth

### Sebastian Marth (view profile)

on 31 Aug 2019
Latest activity Answered by Torsten

### Torsten (view profile)

on 2 Sep 2019
I'm new to matlab so please be lenient :)
So I'm trying to solve a differential equation with the ode45 solver. The problem is the differential equation contains a function which is dependent by the differential equation itself.
I'm trying to calculate the air-density in dependence of the height. The heigth ist the solution of the differential equation.
I hope my problem is understandable.
function ypunktpunkt = Flug_DGL(t,y)
function rohx = Dichte(y)
if y(1) <= 11000
T(y(1)) = 15.04-0.00649*y
p(y(1)) = 101.29*((T(y(1))+273.1)/288.08)^5.256
elseif y(1) > 11000 & y(1) <= 25000
T(y(1)) = -56.46
p(y(1)) = 22.65*exp(1.73-0.000157*y(1))
else y(1) > 25000
T(y(1)) = -131.21+0.00299*y(1)
p(y(1)) = 2.488*((T(y(1))+273.1)/216.6)^(-11.388)
end
rohx(y(1)) = p(y(1))/(0.2896*(T(y(1))+273.1))
end
u = 1500;
m_null = 10000;
m_punkt = 120;
alpa = 45;
R = 8000;
cw = 0.7;
A_front = 8;
roh=Dichte(y)
g_null = 9.81;
ypunktpunkt = [y(2) ; u*sin(alpa)*m_punkt/(m_null-m_punkt*t)-R^2*g_null/(R+y(1))^2-y(2)^2*roh*cw*A_front/2];
end
[t,y] = ode45('Flug_DGL',[1,300],[0;0]);
plot(t,y(:,1));

#### 0 Comments

Sign in to comment.

## 1 Answer

### Torsten (view profile)

Answer by Torsten

### Torsten (view profile)

on 2 Sep 2019

function main
[t,y] = ode45(@Flug_DGL,[1,300],[0;0]);
plot(t,y(:,1));
end
function ypunktpunkt = Flug_DGL(t,y)
u = 1500;
m_null = 10000;
m_punkt = 120;
alpa = 45;
R = 8000;
cw = 0.7;
A_front = 8;
roh = Dichte(y)
g_null = 9.81;
ypunktpunkt = [y(2) ; u*sind(alpa)*m_punkt/(m_null-m_punkt*t)-R^2*g_null/(R+y(1))^2-y(2)^2*roh*cw*A_front/2];
end
function rohx = Dichte(y)
if y(1) <= 11000
T = 15.04-0.00649*y(1);
p = 101.29*((T+273.1)/288.08)^5.256;
elseif y(1) > 11000 & y(1) <= 25000
T = -56.46;
p = 22.65*exp(1.73-0.000157*y(1));
else y(1) > 25000
T = -131.21+0.00299*y(1);
p = 2.488*((T+273.1)/216.6)^(-11.388);
end
rohx = p/(0.2896*(T+273.1))
end

#### 0 Comments

Sign in to comment.