Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MAE 8 - Homework 6 CHAPTER 6 Problem 1. Write a function called mygalaxy to create a model galaxy and return the assigned mass, coordinates,

MAE 8 - Homework 6 CHAPTER 6 Problem 1. Write a function called mygalaxy to create a model galaxy and return the assigned mass, coordinates, and calculated resultant gravitational force for each star. The call to the function should have the form: [mass coord force] = mygalaxy(N, dimX, dimY, dimZ) Input arguments are the number of stars in the galaxy, N, and the galaxy dimensions dimX, dimY, and dimZ. The output values are the mass, mass, the Cartesian coordinates, coord, and resultant force vector, force, associated with each star. The dimensions of output vector mass should be Nx1, so that, for instance, mass(43) stores the assigned mass of the 43rd star. The dimensions of coords and force should be [Nx3], so that, for example, coord(54,2) stores the y-coordinate of the 54th star, and force(12,3) stores the z-coordinate of the resultant gravitational force on the 12th star. The function mygalaxy should use MATLAB function rand to generate the mass and the coordinates for all N stars. The mass of each star should be in the range m 1 10 , 1 10 30 32 (kg), whereas the coordinates should be in the range x 0, dimX , y 0, dimY , z 0, dimZ (meters). The resultant gravitational force Fi acting on any given star i can be computed using Newton's Law of Universal Gravitation, which, extended to a system of stars, takes the form: N Fi G j 1 j i mi m j rij rij 2 rij In the equation above, G = 6.67408 10-11 m3 kg-1 s-2 is the universal gravitational constant, mi and m j are the masses of stars i and j , respectively, and rij is the displacement vector between the two stars, which should be computed in a subfunction called dispvec, according to the formula: rij x j xi , y j yi , z j zi , . Call your function passing to it the following values for input arguments: N = 100; dimX = 1e9; dimY = 1e9; dimZ = 1e9; Using fprintf with formatting, print to screen the mass, coordinates, and force components for a random star of your galaxy. Display the time it took the CPU to perform the programmed computations. This time can be calculated using the tic and toc functions of MATLAB. Now, repeat the call to the function, but setting N = 1000. CHAPTER 7 Problem 2. Write a function wordscramble that will receive a word in a string as an input argument. It will then randomly scramble the letters and return the result. Here is an example of calling the function: >> wordscramble('fantastic') ans = safntcait Problem 3. Write a function namedept that will receive a name and department as separate strings, and will create and return a code consisting of the first two letters of the name and the last two letters of the department. The code should be uppercase letters. For example: >> namedept('Robert','Mechanical') ans = ROAL (Hint: use MATLAB built-in function upper to convert lower case characters to upper case.) Problem 4. Write a script that will prompt the user for a positive number n and a trigonometric function name, such as sin, cos, tan or cot. Create a vector x of 1000 linearly equally spaced points between 0 and n, and a vector y which is either sin(x), cos(x), tan(x) or cot(x), depending on user specification. Then plot with a title that says, e.g. \"sin(x) from [0, n]\" where the value of n is actually in the title

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

Students also viewed these Mathematics questions

Question

Why are employees called internal customers?

Answered: 1 week ago