1. Engineering
  2. Computer Science
  3. objective learn the difference between scripts and functions in matlab...

Question: objective learn the difference between scripts and functions in matlab...

Question details

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 (Earths mass), dist 6.38e6 (distance to Earths 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 (Earths mass), dist 6.38e6 (distance to Earths 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 moons surface to its center), save the file (important, otherwise the changes wont 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

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution