help, my ode is not working. First will be my main code. Second will be the function I am calling for.

%values general
g = 9.81; %[m/s^2]
gc = 6.67.*10.^(-11); %gravitational constant
lm = 21.75; %[m] length missle
cd = .04; %coeffecient of drag, no units
la = 200; %[m] launch altitude
lt = 280; %[K] launch temperature
lp = 102; %[kPa] launch pressure
me = 5.972.*10.^24; %mass of earth
re = 637100; %radius of earth
diaM = 4; %diameter missile [m]
aM = pi*(diaM/2)^2;%area missle 12.57[m^2]
%----------------------------
%launch & stage 1
%----------------------------
%values stage 1
mp1 = 90000; %[kg] mass propellant
mt1 = 100000; %[kg] mass total
ts1 = [0,160]; %[sec] time span
timetotal1 = 160; %[sec]
%---------------------
%visual 1
figure(1)
%import visual 1 data
visual1 = xlsread('visual1.xlsx');
y1 = visual1(:,2);
time1 = visual1(:,1);
%polyfit data points visual 1
p1 = polyfit(time1,y1,2);%creates polynomial; t1-x,y1-y,3rd degree
a1 = p1(1); %tried to do polyval at t=160 and that gave me an insaneeee accleration. Luckily figured this out.
b1 = p1(2);
c1 = p1(3);
hold on
x = time1;
PP1 = @(x) (a1.*x.^2)+(b1.*x)+c1;
plot(time1,PP1(x),':s','MarkerSize',2,'MarkerFaceColor','b');
xlabel('position [meter]')
ylabel('time [sec]')
title('Tracker Data Visuals 1 & 2')
%acceleration for visual one with average acceleration equation below
%---------------------
%visual 2
%data on figure 1 as well (NEW FIGURE?)
%import and graph data visual 2
visual2 = xlsread('visuall2.xlsx');
y2 = visual2(:,2);
t2 = visual2(:,1);
%polyfit data points visual 2
p2 = polyfit(t2,y2,2);%creates polynomial; t2=x,y2=y,2nd degree
a2 = p2(1);
b2 = p2(2);
c2 = p2(3);
hold on
x = t2;
PP2 = @(x) (a2.*x.^2)+(b2.*x)+c2;
%graph
plot(t2,PP2(x),':s','MarkerSize',2,'MarkerFaceColor','r')
%acceleration for visual 2 with average acceleration below
%---------------------
%average acceleration stage 1
ac1 = a1*2; %returns acceleration 6.349 m/s^2
ac2 = a2*2; %returns acceleration 6.6647 m/s^2
aa1 = (ac1+ac2)/2; %returns average acceleration 6.5072 m/s^2
%------------------------
%Thrust stage 1 = thrust launch
%thrust equation -> thrust1 = mass prop * (gravity + avg. acc. stage 1)
tt1 = mt1.*(g+aa1);
%------------------------
PV1 = [re+la,0]; %initial position and velocity - radiues earth + launch altitude, zero initial velocity
%------------------------
%Stage 1 mass flow rate of propellant out
mdot1 = mp1/timetotal1; %mflow = massprop/time stage 1
%mass over time
%------------------------
%ODE function analyzing stage 1 data
[t1,vel1]=ode45(@(t1,s) dynamiteff(t,s(1),s(2),timetotal1,mt1,mp1,tt1),ts1,PV1); %ODE
y1 = vel1(:,1);%position stage 1
v1 = vel1(:,2);%velocity stage 1
%-----------------------
%stage 2
%----------------------
%values stage 2
mt2 = 8000; %[kg] total mass missle
mp2 = 6000; %[kg] mass propellant
ts2 = [160,350]; %[sec] time span
timetotal2 = 350; %[sec] time total
tt2 = 100; %[kN] thrust
%-----------------------
PV2 = [y1(end),v1(end)]; %initial position and velocity - radiues earth, zero initial velocity
%----------------------
%mass flow rate of propellant stage 2
%mdot = mass flow rate
%mdot = mass prop / time span
mdot2 = mp2/ts2;
%-----------------------
%ODE stage 2
[t2,vel2] = ode45(@(t2,s2) dynamiteff(t2,s2(1),s2(2),timetotal2,mt2,mp2,tt2,cd),ts2,PV2); %ODE
%does placement of ; before ode_y create issues?SHOULD BE IN ALL CAPS LOOK AT THIS QUESTION
y2 = vel2(:,1);%position stage 2
v2 = vel2(:,2);%velcoity stage 2
%-----------------------
%stage 3 - coasting stage
%------------------------
%values stage 3
mt3 = 2000; %[kg] coasting mass
mp3 = 0; %mass propellant
mdot3 = 0; %no more propellant, no more flow rate
tt3 = 0; %coasting.. no thrust
%-----------------------
PV3 = [y2(end),v2(end)]; %initial position and velocity - radiues earth, zero initial velocity
%------------------------
%ODE stage 3
[t3,vel3] = ode45(@(t3,s3) dynamiteff(t3,s3(1),s3(2),timetotal3,mt3,mp3,tt3,cd),ts3,PV3); %ODE
%does placement of ; before ode_y create issues?SHOULD BE IN ALL CAPS LOOK AT THIS QUESTION
y3 = vel3(:,1);%position stage 2
v3 = vel3(:,2);%velcoity stage 2
%------------------------------function dynamiteff----------------------------------------
function dynamite = dynamiteff(t, lm, v, timetotal, mt1, mp1,tt1,cd)
%function(time,length missle, velocity, mass total, initial mass
%propellant, thrust1, coefficient of drag).*10.^(-11)
gc = 6.67.*10.^(-11); %gravitational constant
me = 5.972.*10.^24; %mass of earth
re = 637100; %radius of earth
lp = 102; %[kPa] launch pressure
lt = 280; %[K] launch temperature
%mp1 = mass propellant
%mdot = mass flow rate
%tt1 = thrust
%Pd = force drag
%Fg = force gravity
%lm = length rocket
%v = velocity
rho=standardTable(lp,lt,lm); %launch pressure, launch temp, length rocket
diaM = 4; %diameter missile [m]
aM = ((diaM./2).^2).*pi;%area missle [m^2]
if v>0
Pd=.5.*rho.*cd.*aM.*rho.*v.^2; %force drag = #*rho#coefficient of drag *area of missle * rho * velocity^2
else
Pd=0; %force drag = 0
end
mdot=mp1/timetotal;%mass flow rate = mass propellant/total time
mass=mt1-t.*mdot;%mass = mass total - time * fuel consumption
Fg=gc*me/(re+lm).^2;%force gravity = gravitational constant * mass earth / (radius earth + length missle)
dynamite=zeros(2,1);%two rows one column, create zeros to find velocity and thrust
dynamite(1)=(velocity);
dynamite(2)=(tt1-Pd-Fg)/mass;
end

5 Comments

project1
Undefined function or variable 'lm'.
Error in standardTable (line 7)
P = lp*(1-(L*r/lt0)).^(g*M/(R*lm)); %[kPa]
Error in dynamiteff (line 20)
rho=standardTable(lp,lt,lm); %launch pressure, launch temp, length rocket
Error in project1>@(t1,s)dynamiteff(t,s(1),s(2),timetotal1,mt1,mp1,tt1)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in project1 (line 99)
[t1,vel1]=ode45(@(t1,s) dynamiteff(t,s(1),s(2),timetotal1,mt1,mp1,tt1),ts1,PV1); %ODE
here is the standard table i am using
function rho = standardTable(lp,lt0,r)
rho = zeros(1,length(r));
g = 9.81; %[m/s^2]
L = 0.0065; %[K/m]
M = 0.0289644; %[kg/mol]
R = 8.31447; %[J/mol*k]
P = lp*(1-(L*r/lt0)).^(g*M/(R*lm)); %[kPa]
lt = lt0 - L*r; %[K]
for ii = 1:(length(r))
rho(ii) = 1000*P(ii)*M./(R*lt(ii));
if isreal(rho(ii)) == 0 || isnan(rho(ii)) == 1
rho(ii) = 0;
end
end
end
here is the one they gave me... but I switched it up to match my file, not sure if i needed to
function rho = standardTable(P0,T0,r)
rho = zeros(1,length(r));
g = 9.81; %[m/s^2]
L = 0.0065; %[K/m]
M = 0.0289644; %[kg/mol]
R = 8.31447; %[J/mol*k]
P = P0*(1-(L*r/T0)).^(g*M/(R*L)); %[kPa]
T = T0 - L*r; %[K]
for ii = 1:(length(r))
rho(ii) = 1000*P(ii)*M./(R*T(ii));
if isreal(rho(ii)) == 0 || isnan(rho(ii)) == 1
rho(ii) = 0;
end
end
end
You must replace "lm" by "L" in the line
P = lp*(1-(L*r/lt0)).^(g*M/(R*lm)); %[kPa]
or you must replace
L = 0.0065; %[K/m]
by
lm = 0.0065; %[K/m]

Sign in to comment.

Answers (1)

The last argument (cd) is missing in the call to "dynamiteff" in the line
[t1,vel1]=ode45(@(t1,s) dynamiteff(t,s(1),s(2),timetotal1,mt1,mp1,tt1),ts1,PV1);
Best wishes
Torsten.

Categories

Find more on Gravitation, Cosmology & Astrophysics in Help Center and File Exchange

Commented:

on 21 Nov 2018

Community Treasure Hunt

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

Start Hunting!