Two Stage Rocket zeroing a value and indices must be a positive real interger?

3 visualizzazioni (ultimi 30 giorni)
if true
function TWOSTGSPR
clc
clear all
%%Part A
%%Variables
g0 = 9.81; % gravity
m01 = 249.5; m02 = 113.4; % Intial mass of rocket
mf1 = 170.1; mf2 = 58.97; % Mass of rocket after an engine burn over a period of delta T
rme1 = 11.1; rme2 = 4.05; % Rate at which exhaust mass flows accross the nozzle exit plane
Isp1 = 235; Isp2 = 310; % Impulse
c1 = Isp1*g0; c2 = Isp2*g0; %
%%Stage 1
ts1bo = (m01-mf1)/rme1; % Time till burnout stage 1
ts1 = ts1bo+3; % Time after delay
hs1bo = (c1/rme1)*(mf1*log(mf1/m01)+m01-mf1)-0.5*(((m01-mf1)/rme1)^2*g0); % Stage 1 Burnout Height
vs1bo = c1*log(m01/mf1)-g0*((m01-mf1)/rme1);
vs1bo3 = vs1bo-g0*(ts1-ts1bo);
hs1bo3 = hs1bo + vs1bo3*(ts1-ts1bo)-0.5*g0*(ts1-ts1bo)^2;
%%Stage 2
ts2max = (m02-mf2)/rme2;
ts2bo = (m02-mf2)/rme2; % Time till burnout stage 2
vs2bo = c2*log(m02/mf2)-g0*((m02-mf2)/rme2);
hs2bo = hs1bo3+(c2/rme2)*(mf2*log(mf2/m02)+m02-mf2)-0.5*(((m02-mf2)/rme2)^2*g0); % Stage 2 Burnout Height
%%Max Height
n = m02/mf2; % A constant with a variable of n
hmax = hs1bo3+0.5*((c2^2)/g0)*(log(n)^2)-(c2/rme2)*m02*((n*log(n)-(n-1))/n); % Max Height
%%Display
fprintf("Height at Burnout in First Stage: %gm \nHeight at Burnout in Second Stage: %gm \nMax Height: %gm ",hs1bo, hs2bo, hmax);
%%Part B
t1 = 0:0.001:ts1;
t1a = ts1bo:0.001:ts1;
hs1 = (c1/rme1)*((m01-rme1*t1).*log((m01-rme1*t1)/m01)+rme1*t1)-(0.5.*(t1.^2)*g0);
vs13 = vs1bo - g0*(t1-ts1bo);
hs13 = hs1bo+vs1bo.*(t1-ts1bo)-0.5*g0*((t1-ts1bo).^2);
if t1<=ts1bo
h1 = hs1;
elseif t1>ts1bo
h1 = hs13;
end
plot(t1,h1,'b')
hold on
%
t1 = 0:0.001:ts1;
hs1 = (c1/rme1)*((m01-rme1*t1).*log((m01-rme1*t1)/m01)+rme1*t1)-(0.5.*(t1.^2)*g0);
end
  3 Commenti
Stephen23
Stephen23 il 22 Mar 2018
@David Oshidero: we cannot guess where the error occurs or what it says exactly. Please show us the complete error message. This means all of the red text.
David Oshidero
David Oshidero il 22 Mar 2018
Modificato: Image Analyst il 22 Mar 2018
The error I'm getting, at this point in time, is this one, after changing the code:
Matrix dimensions must agree.
Error in TWOSTGSPR (line 34)
hs13 = hs1bo+vs1bo.*(t1-ts1bo)-0.5*g0*((t1a-ts1bo).^2);
edit:
That was due to my error. I just realised I used two different t1.

Accedi per commentare.

Risposte (2)

James Tursa
James Tursa il 22 Mar 2018
Modificato: James Tursa il 22 Mar 2018
In this line:
hs13 = hs1bo+vs1bo(t1-ts1bo)-0.5*g0*((t1a-ts1bo).^2);
This
vs1bo(t1-ts1bo)
was probably meant to be this:
vs1bo*(t1-ts1bo)
But then you will have a dimension mismatch error to fix. So maybe you also need to change the t1 to t1a or vice-versa?
Also, I doubt that the if-test here is doing what you think it is doing since t1 is a vector and not a scalar:
if t1<=ts1bo
h1 = hs1;
elseif t1>ts1bo
vs13 = vs1bo - g0*(t1-ts1bo);
h1 = hs13;
end
You should re-examine this if-test to see what it should really be.
  2 Commenti
David Oshidero
David Oshidero il 22 Mar 2018
I will recheck my code once i am home. there was a few things I didn't understand whilst doing it but I thought it would work. thanks for the help ill give a proper reply after trying again
David Oshidero
David Oshidero il 22 Mar 2018
with the time, how would i go about fixing the dimensions? What im trying to do is get the code to use that formula if the time is greater than the burnout time tsbo, and use the initial formula if its less. But to make that work i had to do it that way however the vs13 formula needs to run only if the time is greater than the burnout time. I started getting problems everywhere so thought I would try find some help. Thanks

Accedi per commentare.


David Oshidero
David Oshidero il 23 Mar 2018
I have updated the code to where I am at so far, and for some reason i am getting this error? Reference to a cleared variable h1.
Error in TWOSTGSPR (line 40) plot(t1,h1,'b')
im wondering what it means by a cleared variable?

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by