Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

I wrote a code for determining the volume need for each stage of a rocket

Asked by Steven

Steven (view profile)

on 28 Jul 2013
clear;clc
%create the statement
radius1=16.5;height1=138.0;radius2=16.5;height2=81.5;radius=30.8;height3=61.6;
height=input('Enter a value for height');
volume=(height)
if height<=138
   volume=(pi*height*radius1^2)
   disp(volume)
elseif height<=219.5
    volume=(pi*height1*radius1^2+pi*(138-height)*radius2^2)
    disp(volume)
elseif height<=281.1
   volume=(pi*height1*radius1^2+pi*(138-height)*radius2^2+pi*(219.5-height)*radius3^2)
   disp(volume)
else height>281.1
    disp(-1)
end

I run it through the checker and the code is still wrong when I run it through the grader. What might I be doing wrong in writing my code. I gave the height and radius in each stage above and I am using the volume formula for a cylinder.

1 Comment

dpb

dpb (view profile)

on 28 Jul 2013

What should the net height be of higher stages????

Steven

Steven (view profile)

Tags

Products

No products are associated with this question.

1 Answer

Answer by Youssef KHMOU

Youssef KHMOU (view profile)

on 28 Jul 2013

Steven, The error i can see is that the volume is negative, because you substract the height from 138 & 219.5 while its the reverse, try this version :

clear;
radius1=16.5; height1=138.0;
radius2=16.5; height2=81.5;
radius3=30.8; height3=61.6;
height=input('Enter a value for height:\n');
if height<=138
 volume=(pi*height*radius1^2);
elseif (height>138) && (height<=219.5)
  volume=(pi*height1*radius1^2+pi*(height-138.00)*radius2^2);
elseif (height>219.5)&&(height<=281.1)
 volume=(pi*height1*radius1^2) + (pi*(height-138.00)*radius2^2) + ...
     (pi*(height-219.5)*radius3^2);
elseif height>281.1
  error(' Maximum height exceeded hmax=281.1');
end
fprintf(' Volume=%.2f m^3\n',volume);

1 Comment

dpb

dpb (view profile)

on 28 Jul 2013

I'd preferred the hint version for HW problems instead of just doing it for the poster...but that's me.

Youssef  KHMOU

Youssef KHMOU (view profile)

Contact us