Question

Matlab code 3. Create a units convertor for measures of volume. Ex: How many liters are...

Matlab code

3. Create a units convertor for measures of volume. Ex: How many liters are in 10 gallons – answer is 37.8541. a. Create input statements that ask for a quantity and a set of possible units. The possible units are cubic meters, cubic feet, liters, or US gallons. b. Create an input statement to ask for the converted unit. c. Use if statements to perform the conversion. d. Use fprintf to display the conversion in a meaningful way (i.e. don’t just print the new quantity).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sol:

clc
clear all
iu=input('Enter input unit:\n1 For cubic meters\n2 For Cubic feet\n3 For liters\n4 For Us gallons\n input unit value=');
V=input('Enter the Numerical value of volume:');
if(iu==1)
v_cm=V;
else if(iu==2)
v_cm=0.0283168*V;
else if (iu==3)
v_cm=.001*V;
else if (iu==4)
v_cm=0.00378541*V;
else disp('Enter the correct value')
end
end
end
end
ou=input('Enter output unit:\n1 For cubic meters\n2 For Cubic feet\n3 For cubic liters\n4 For Us gallons\noutput unit value=');
if(ou==1)
V_o=v_cm;
fprintf('Volume=%4.4f m^3',V_o)
else if (ou==2)
V_o=35.3147*v_cm;
fprintf('Volume=%4.4f ft^3',V_o)
else if (ou==3)
V_o=1000*v_cm;
fprintf('Volume=%4.4f liters',V_o)
else if (ou==4)
V_o=264.172*v_cm;
fprintf('Volume=%4.4f Us gallons',V_o)

else disp('Please Enter the correct value')
end
end
end
end
  

Add a comment
Know the answer?
Add Answer to:
Matlab code 3. Create a units convertor for measures of volume. Ex: How many liters are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MATLAB Questions. I have a basic understanding of the tools for MATLAB, but do not know...

    MATLAB Questions. I have a basic understanding of the tools for MATLAB, but do not know how to create the code for these questions. Please show the entire code. 2. A paper cup shaped as a frustum of cone with R-14R1 is designed to have a volume of 25 cm Determine R1, R2 and the surface area, S, of the paper for cups with a height, h, of 1O cm. The volume of the cup, V, and the surface area...

  • code in C++ Create a program that uses the pass by reference operator instead of the...

    code in C++ Create a program that uses the pass by reference operator instead of the return command. Your main program will need to: create empty variables call void function 1 with no input to display your name to the screen call function 2 to collect the square feet that a gallon of paint covers from user call function 2 to collect the square feet of wall that needs to be painted call function 3 to calculate the number of...

  • Matlab help *****CONSTANT***** NUM_MONTHS = 12; FIRST_YEAR = 2013; LAST_YEAR = 2016; %*****...

    matlab help *****CONSTANT***** NUM_MONTHS = 12; FIRST_YEAR = 2013; LAST_YEAR = 2016; %*****INPUT***** months = 1:NUM_MONTHS; years = FIRST_YEAR:LAST_YEAR; % read data file lake_powell = load( 'lake_powell.txt' ); % OR load lake_powell.txt % print with title and year column headings. fprintf(' Lake Powell Water Levels (in feet)\n') fprintf('%8d ', years) fprintf('\n') % print contents of lake_powell for month = 1:NUM_MONTHS fprintf('%9.2f', lake_powell(month,:)) fprintf('\n') end % PART B ========================================================== fprintf('\nPART B: Determine average elevation of water level for each year and...

  • I need help solving these questions,please don’t know how to solve it by using matlab.!

    i need help solving these questions,please don’t know how to solve it by using matlab.! Solve the following questions Ol: You are required to develop a script to calculate the volume of a pyramid, which is 1/3 *base *height, where the base is length *width. Prompt the user to enter values for the length, width, and height, and then calculate the volume of the pyramid. When the user enters each value, he or she will then also be prompted to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT