Concept explainers
A rod on the surface of Jupiter's moon Callisto has a volume measured in cubic meters. Write a MATLAB program that will ask the user to type in the volume in cubic meters in order to determine the weight of the rod in units of pounds-force. The specific gravity of the rod is 4. 7. Gravitational acceleration on Callisto is 1.25 meters per second squared. The input and output of the program should look similar to the output that follows. Be sure to report the weight as an integer value. If the user types a negative number or a number greater than 500 cubic meters for the volume of the rod, your program should display an error message using the error function indicating that the provided input is outside of the desired range and terminate.
Sample Input/Output (three examples)
Enter the volume of the rod [cubic meters) : - 10
Error Volume must be between 0 and 500 cubic meters
Enter the Volume of the rod [cubic meters): 501
Error: Volume must be between 0 and 500 cubic meters
Enter the volume of the rod [cubic meters]: 0.3
The weight of the rod is 391 pounds-force.
Want to see the full answer?
Check out a sample textbook solutionChapter 19 Solutions
Thinking Like an Engineer: An Active Learning Approach (3rd Edition)
- I was going over the equations for the notes in class and I had a thought. Based on the equations in the image, you could get negative propellant mass. So, I coded it in matlab and I got negative mass. How is that possible? I think I used practical values for the velocity and mass ratio and so on. Did I do something wrong?arrow_forwardMatlab Codearrow_forwardHi I need help to make the line change into a different color, I half of the line to be orange and I need the other half of the line towards the end to be purple as shown in the picture. Also I need there be a box saying Diesel, petrol, diesel best fit, petrol best fit. This part is also shown in the graph. Please use this code and fix it in MATLAB: % Sample data for Diesel and Petrol cars carPosition = linspace(1, 60, 50); % Assumed positions of cars % Fix the random seed for reproducibility rng(50); % Assumed positions of cars CO2Diesel = 25 + 5*cos(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Diesel CO2Petrol = 20 + 5*sin(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Petrol % Fit polynomial curves pDiesel = polyfit(carPosition, CO2Diesel, 3); pPetrol = polyfit(carPosition, CO2Petrol, 3); % Generate points for best fit lines fitDiesel = polyval(pDiesel, carPosition); fitPetrol = polyval(pPetrol, carPosition); % Combine the best fit lines combinedFit =…arrow_forward
- 3) Body mass index (BMI) of a person is a measure of body fat based on height and weight. In U.S. customary units it is calculated by: BMI = 703" %D where W is the person's weight in pounds and h is the heights in inches. Write a MATLAB program in a script file that calculates the BMI. For input the program asks the user to enter his/her weight and height. The pro- gram then calculates the BMI rounded to the nearest tenth. For output the program displays the message: "The BMI is: XX." where XX is the value of the BMI. Determine the BMI of a 68-in.-tall person that weigh162 lb.arrow_forwardQ4: Create a Visual Basic Project to find the value of the following series: h? h4 h3 cos(h) = h – 2! 3! 4! Write the code program so that the value of angle (h) is entered into inputbox. Estimate the value of series (cos(h)) so that the absolute value of any term is greater or equal to 10-6. Display the required number of terms (N) which it used in this series in a text box and display the result of series (cos(h)) in another separate text box.arrow_forwardI’m making the graph that you see in the picture but the code that I’m using makes the line with to many curves. Could you make the lines look like the one that you see on the graph. Don’t change the color just make it with a little bit less curves like you see in the picture. Use this code on MATLAB and fix it. % Sample data for Diesel and Petrol cars carPosition = linspace(1, 60, 50); % Assumed positions of cars % Fix the random seed for reproducibility rng(50); % Assumed CO2 emissions for Diesel and Petrol CO2Diesel = 25 + 5*cos(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Diesel CO2Petrol = 20 + 5*sin(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Petrol % Fit polynomial curves pDiesel = polyfit(carPosition, CO2Diesel, 3); pPetrol = polyfit(carPosition, CO2Petrol, 3); % Generate points for best fit lines fitDiesel = polyval(pDiesel, carPosition); fitPetrol = polyval(pPetrol, carPosition); % Combined best fit combinedFit = (fitDiesel + fitPetrol) / 2;…arrow_forward
- The picture that has two graphs are generated by this code. Every time I run it on MATLAB it keeps generating graphs with different curves. The picture that shows one graph is the curve that I want to keep. Please keep the color of the lines and the circles and keep the title of the graph the same. I want everything to be the same except I want the line to look exactly like the picture with one graph on it. Use this code on MATLAB and fix it and then send the correct code back please. % Sample data for Diesel and Petrol cars carPosition = linspace(1, 60, 50); % Assumed positions of cars % Use the 'seed' function instead of 'rng' seed = 50; % Define your seed here rand('seed',seed); % Assumed CO2 emissions for Diesel and Petrol CO2Diesel = 25 + 5*cos(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Diesel CO2Petrol = 20 + 5*sin(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Petrol % Fit polynomial curves with a reduced degree of 2 pDiesel = polyfit(carPosition,…arrow_forwardI need help with the purple line the line that you see one the graph on the picture needs to be on the graph. Use this code to add the purple line and make sure it’s crossing the orange line. Please make sure the lines are positioned the same way it is shown on the picture with the graph. Use this code on MATLAB and add the purple line. % Sample data for Diesel and Petrol cars carPosition = linspace(1, 60, 50); % Assumed positions of cars % Use the 'seed' function instead of 'rng' seed = 50; % Define your seed here rand('seed',seed); % Assumed CO2 emissions for Diesel and Petrol CO2Diesel = 25 + 5*cos(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Diesel CO2Petrol = 20 + 5*sin(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Petrol % Fit polynomial curves with a reduced degree of 2 pDiesel = polyfit(carPosition, CO2Diesel, 2); pPetrol = polyfit(carPosition, CO2Petrol, 2); % Generate points for best fit lines fitDiesel = polyval(pDiesel, carPosition);…arrow_forwardI’m using this code in MATLAB but for some odd reason every time I run it on MATLAB I keep on getting a different graphs. In the picture that shows two different graphs are from the same code, but I need to it to look like the picture that has one graph. Could you please fix it. To make it look like the picture that has one graph? Here is the code: % Sample data for Diesel and Petrol carPosition = linspace(1, 60, 50); % Assumed positions of cars CO2Diesel = 25 + 5*cos(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Diesel CO2Petrol = 20 + 5*sin(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Petrol % Fit polynomial curves pDiesel = polyfit(carPosition, CO2Diesel, 3); pPetrol = polyfit(carPosition, CO2Petrol, 3); % Generate points for best fit lines fitDiesel = polyval(pDiesel, carPosition); fitPetrol = polyval(pPetrol, carPosition); % Plotting the data figure; hold on; scatter(carPosition, CO2Diesel, 'o', 'MarkerEdgeColor', [1 0.5 0]); % Diesel data…arrow_forward
- There is a small space between the orange and purple line could you please connect the two lines together also can you please make the purple line shorter and then connect the purple line to the orange line, please take out the box that says “Diesel, petrol, Diesel best fit, petrol best fit”. Also when ever I run this code the graph shows up but there are still errors that comes up could you please fix them when you are running this on MATLAB. Please use this code on MATLAB and fix it. % Sample data for Diesel and Petrol cars carPosition = linspace(1, 60, 50); % Assumed positions of cars % Fix the random seed for reproducibility rng(50); % Assumed CO2 emissions for Diesel and Petrol CO2Diesel = 25 + 5*cos(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Diesel CO2Petrol = 20 + 5*sin(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Petrol % Fit polynomial curves pDiesel = polyfit(carPosition, CO2Diesel, 3); pPetrol = polyfit(carPosition, CO2Petrol, 3); % Generate…arrow_forwardPlease state the formulas used and write the answers clearly and completely. Include also the free body diagram. Thank you!arrow_forwardHi, I need help with the first part of the problem below because I'm very confused about how P1 and P2 should be calculated. If you look at my notes to solve the problem there is already a formula in place as I always thought the Patm should also be multiplied by the Area in the numerator, but it's not if I look at this specific tutorial solution given by my course but it's not explained why. I have done a while ago a very similar problem with using that formula in my notes and it gave me the right results, but it's not working for this one. Could you please help me understand why as I have a test coming soon? Figure Q3 (see image attached) shows a cylinder and pistonenclosing air, the movement of the pistonbeing restrained by a compression spring ofstiffness 20 kN/m. The air is heated andexpands, the piston moving 0.3 m. Thefree length of the spring is 1.0 m.Calculate the work done by the air duringthe process.If the pressure , volume and internal energyof air are related by the…arrow_forward
- Elements Of ElectromagneticsMechanical EngineeringISBN:9780190698614Author:Sadiku, Matthew N. O.Publisher:Oxford University PressMechanics of Materials (10th Edition)Mechanical EngineeringISBN:9780134319650Author:Russell C. HibbelerPublisher:PEARSONThermodynamics: An Engineering ApproachMechanical EngineeringISBN:9781259822674Author:Yunus A. Cengel Dr., Michael A. BolesPublisher:McGraw-Hill Education
- Control Systems EngineeringMechanical EngineeringISBN:9781118170519Author:Norman S. NisePublisher:WILEYMechanics of Materials (MindTap Course List)Mechanical EngineeringISBN:9781337093347Author:Barry J. Goodno, James M. GerePublisher:Cengage LearningEngineering Mechanics: StaticsMechanical EngineeringISBN:9781118807330Author:James L. Meriam, L. G. Kraige, J. N. BoltonPublisher:WILEY