Question: Write MATLAB code to modify the previous gravity calculation examples as follows (see below for original prompt): If the user enters a zero value

Write MATLAB code to modify the previous gravity calculation examples as follows 

Write MATLAB code to modify the previous gravity calculation examples as follows (see below for original prompt): If the user enters a zero value for mass, an error message will be generated and the program will terminate; if the user enters a negative value for mass, the program will issue an appropriate warning message and calculate the gravity by using the absolute value of the mass; for strictly positive masses, the program will calculate gravity in the normal manner. Original Prompt: We are given the weight (in variable w) in newtons of an object as well as the mass (in variable m) in kilograms and want to determine the gravity in meters per second squared. To solve this, we will use the equation g = w/m, but we want to wrap that expression inside a conditional just in case the user provides a zero mass, which does not make sense in our situation, but will not cause an error in MATLAB-if you divide a number by 0 in MATLAB, the value "Inf" is calculated, which represents infinity.

Step by Step Solution

3.39 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Matlab function g gravityw m This function calculates the gravity g in meters per second squared for an object with weight w in newtons and mass m in ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!