Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective: Learn the difference between scripts and functions in MATLAB by writing a script to calculate the force and then converting it into a function

image text in transcribed

image text in transcribed

Objective: Learn the difference between scripts and functions in MATLAB by writing a script to calculate the force and then converting it into a function that is called within a test script. To complete this assignment, you must write two MATLAB files: File Name Description Gravity.m A MATLAB script implementing the algorithm to compute the force of between two objects separated by a certain distance Gravity func.m A MATLAB function that implements the same algorithm as Gravity.m, but as a function rather than a script Algorithm: You should compute the force of gravity F (in Newtons) between two objects of mass m, and m. (in kilograms) and separated by distance d (in meters). The formula to compute F is: d2 where g is the gravitational constant, 6.67 x 10-11 Problem 3 (40 points) (Gravity.m): 1. Start by Click on New Script in MATLAB, and save the file as Gravity.m Next, type statements that set mass 1 60(approximate mass of a human). mass2 -5. 97219e24 (Earth's mass), dist 6.38e6 (distance to Earth's centen), and conste - 6.67e-11 (the gravitational constant). End each statement with a semicolon to suppress output. Then type a statement that computes gravity force and place the answer in the variable forced. Do not suppress the output. Press "Save" to save the script contents to the file. - * . - Problem 3 (40 points) (Gravity.m): 1. Start by . Click on New Script in MATLAB, and save the file as Gravity.m . Next, type statements that set massi 60 (approximate mass of a human), mass2 -5,97219e24 (Earth's mass), dist 6.38e6 (distance to Earth's center), and constG6.67e-11 (the gravitational constant). End each statement with a semicolon to suppress output . Then type a statement that computes gravity force and place the answer in the variable forceG. Do not suppress the output. Press "Save" to save the script contents to the file. Now run the script by typing "Gravity on the command line. The output should be forceG- 587.1774. 2. In the script file, change mass2 to 7.34767309e22 (the mass of the moon) . and dist to 1737400 (distance from moon's surface to its center), save the file (important, otherwise the changes won't take effect) Now run the script again by typing "Gravity" on the command line (or use the up- arrow key), The output should now be 97 4153 3. 4. Add comments to your script 5. Submit your script file to Blackboard

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899