TRAIN Scholarship Week 11 MATLAB

 Genaro Rivera

December 2, 2022

MATLAB user-defined functions

This week I decided to make a script that computes the gravitational force (in Newtons) between two bodies (m1 and m2) in kg and distance (r). Specifically, the force between the Earth (5.97*10^24 kg and 6371 km) and I. To make things simpler I decided to break the script into three user-defined functions.



This week I went over user-defined functions. A user defined function is unique. For example, a built-in function would be something like the max function (finds the highest point) or the avg function (finds the average from a list of numbers) where MATLAB computes the function in the background. A user defined function does the same except, the user makes and customizes the function. Above is an example of a function I made that converts between pounds (my weight of 120 lbs) and kilograms. To convert from pounds to kilograms, I selected option 1 ([Weight] = Pound_Kilogram(120, 1)). The second picture is an example of the user defined function in use without the need to display all the work. This is useful for simplifying the look of longer functions.
Building off the previous idea, I decided to make a function that converts between kilometers and meters.
Furthermore, I created a function that uses the formula for the gravitational force between two bodies given the two masses and distance.

I pieced the three user-defined functions, and created a script that computes the force of gravity between the Earth and I given two masses and the distance. If not for the usrr-defined functions, the base script would look more complicated.









Comments

Post a Comment

Popular posts from this blog

Weather Balloon Spring Flight

System Block Diagrams Introduction Week 5

Temperature Sensor week 8