OBJECTIVE Practice problem solving and scripting in MATLAB Y

OBJECTIVE: Practice problem solving and scripting in MATLAB.

You should work on this task individually.

You are an exobiologist investigating the possibility and potential for life on other planets. As part of your analysis of new planets, you calculate the weight that a specimen from Earth would have on the exoplanet.

Write a script named exoweight.m that, when run, prompts the user to enter the name, estimated mass (in kg), and estimated radius (in km) of the exoplanet, as well as the mass (in kg) of the specimen. From this information, calculate the estimated weight (in Newtons) of the specimen on the exoplanet. Display the result with 1 digit after the decimal.

Hints:

how do you get text input from the user?

how do you create a formatted string?

how do you evaluate a string to obtain a number?

how do you control precision when printing floating point numbers?

Example: (your screen will look similar upon running your script)

>> exoweight

What is the name of the exoplanet? Kepler-452b

What is the estimated mass of Kepler-452b (kg)? 2.635e25

What is the estimated radius of Kepler-452b (km)? 10385

What is the mass of the specimen (kg)? 72.5

On Kepler-452b, it would weigh approximately 1182.2 Newtons.

>>

Remember: All your submitted MATLAB files should start with the header defined in the in-class activity.

Submit exoweight.m to the proper submission box on eCampus.

Solution

clc;
clear all;
name=input(\'What is the name of the exoplanet? \',\'s\');% name of the planet

M=input(\'What is the estimated mass of exoplanet (kg)? \');% mass of exoplanet
R=input(\'What is the estimated radius of exoplanet (km)? \');%radius of exoplanet
m=input(\'What is the mass of the specimen (kg)? \'); %mass of specimen
G=6.674*10^-11; %gravitational constant
Rm=R*1000; %radius in meters
F=(G*M*m)/Rm^2; %Force
Fout=sprintf(\'%.1f\',F); % Force for 1 digit decimal


disp([\'On \',name, \' it would weigh approximately \',Fout,\' Newtons\']); % displays as string

OBJECTIVE: Practice problem solving and scripting in MATLAB. You should work on this task individually. You are an exobiologist investigating the possibility an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site