Solved by Expert Tutors
ENGR 121: It is due May 8, 2016, by 11:59 pm.
Solved by Expert Tutors
Question

# Two MatLab problems. You need MatLab to check if your answer is correct or not.

I`m also attaching a file which has very similar 2 problems, only different numbers.

ENGR 121: Computation Lab I Programming Assignment 1 This assignment comprises of two questions. It is due May 8, 2016, by 11:59 pm. Please read the Submission Instructions section towards the end of this document that describes how to package your code and submit it on-line using the BBLearn system. 1. ( 10 points ) In the absence of air resistance, the Cartesian coordinates of a projectile launched with an initial velocity v 0 (m/s) and angle θ 0 (degrees) can be computed with x = v 0 cos( θ 0 ) t y = v 0 sin( θ 0 ) t - 0 . 5 gt 2 where g is the gravitational acceleration (= 9.81 m / s 2 ) and t is the time (s). Assume that v 0 = 5 m/s and write a well commented MATLAB script to generate a plot of the projectile’s trajectory for various initial angles ranging from 15 to 75 in increments of 15 . Note that θ 0 is in degrees and so use the appropriate MATLAB functions, sind and cosd , to obtain the corresponding trigonometric values. Generate a vector for t from 0 to 3 seconds in increments of 1/128 s. Generate a single plot of the height achieved ( y ) versus horizontal distance ( x ) for each of the initial angles. Label the axes appropriately and use a legend to distinguish among the different cases. Scale the plot such that the minimum height is zero using the axis command. The following plot shows two such trajectories corresponding to launch angles of 45 and 60 , respectively. 0 0.5 1 1.5 2 2.5 3 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 Horizontal distance, x, (m) Height, y, (m) Projectile Motion Initial angle = 45 o Initial angle = 60 o 1
2. ( 10 points ) The Maclaurin series expansion for the cosine function up to some order n is given by cos( x ) = 1 - x 2 2! + x 4 4! - x 6 6! + x 8 8! - · · · , x n n ! , where x is the angle in radians and n ! denotes the factorial of n . So, the cosine approximations for n = 4 , n = 6 , and n = 10 are as follows: cos( x ) = 1 - x 2 2! + x 4 4! cos( x ) = 1 - x 2 2! + x 4 4! - x 6 6! cos( x ) = 1 - x 2 2! + x 4 4! - x 6 6! + x 8 8! - x 10 10! Write a function cosineApprox that takes scalar input arguments x and n , and returns the approximate value of cos( x ) . So, the function will be invoked as follows: approx = cosineApprox(x, n); Use the built-in MATLAB function factorial when computing the series expansion. Assume that x is in radians. Examples of correct function behavior for various values of x and n follow: >> x = pi/3; n = 4; >> approx = cosineApprox(x, n) approx = 0.5018 >> n = 8; >> approx = cosineApprox(x, n) approx = 0.5000 >> x = 2/3 * pi; n = 4; >> approx = cosineApprox(x, n) approx = -0.3915 >> n = 12; >> approx = cosineApprox(x, n) approx = -0.5000 Finally, note that your code should use MATLAB’s built-in vector operations to solve this problem. You must not use for and while loops. 2
Show entire document
ENGR 121: Computation Lab I Solution Set for Programming Assignment 1 1. In the absence of air resistance, the Cartesian coordinates of a projectile launched with an initial velocity v 0 (m/s) and angle θ 0 (degrees) can be computed with x = v 0 cos( θ 0 ) t, y = v 0 sin( θ 0 ) t 0 . 5 gt 2 , where g is the gravitational acceleration (= 9.81 m / s 2 )and t is the time (s). Assume that v 0 =8 m/s and write a well commented MATLAB script to generate a plotoftheprojectile’strajectoryfor various initial angles ranging from 60 to 75 in increments of 5 .No tetha t θ 0 is in degrees and so use the appropriate MATLAB functions, sind and cosd ,toobtainthecorrespondingtrigonometric values. Generate a vector for t from 0s to 8s in increments of 1/128s. Generate a single plot of the height achieved ( y )ve rsusho r izon ta ld is tance( x )fo reacho fthe initial angles. Label the axes appropriately and use a legendtod is t ingu ishamongthed if fe ren t cases. Scale the plot such that the minimum height is zero using the axis command. 1 %% Script to calculate the projectile motion 2 clc; 3 clear all; 4 close all; 5 6 g=9.81 ; 7 v0 = 8; 8 t=0:1/128:8; 9 theta0 = 60:5:75; 10 11 cc = hsv(length(theta0)); %G e n e r a t ec o l o rm a p 12 figure; 13 hold all; 14 15 for i=1 : l e n g t h ( t h e t a 0 ) 16 %t h e t a=t h e t a 0 ( i ) * pi/180; 17 theta = theta0(i); 18 x=v 0 * cosd(theta) * t; 19 y=v 0 * sind(theta) * t-0 . 5 * g * t.ˆ2; 20 plot(x, y, 'color' ,cc(i,:) , 'DisplayName' ,[ 'Initial angle = ' ... num2str(theta) 'ˆo' ]); 21 end 22 legend(gca, 'show' ); 23 ymax = max(y); 24 axis([0 8 0 ymax]); 25 xlabel( 'Horizontal distance, x, (m)' ); 26 ylabel( 'Height, y, (m)' ); 27 title( 'Projectile motion' ); 1 https://www.coursehero.com/file/13145602/Assignment-1-Solution-Keypdf/ This study resource was shared via CourseHero.com
2. Medical studies have established that a bungee jumper’s chances of sustaining a signiFcant vertebrae injury increase signiFcantly if the free-fall velocity exceeds 40 m/s after 5s of free fall. Your boss at the company wants you to determine the mass at which this criterion is exceeded given a drag coefFcient of 0.35 kg/m. The following analytical equation can be used to predict fall velocity as a function of time: v ( t )= r g × m C d tanh t × r g × C d m ! Here, v is the downward vertical velocity (m/s), t is the time (s), g is the acceleration due to gravity (= 9.81 m/s 2 ), C d is the drag coefFcient (kg/m), and m is the jumper’s mass (kg). Try as you might, you cannot manipulate this equation to explicitly solve for m —that is, you cannot isolate the mass on the left side of the equation. So, an alternative way of looking at the problem involves subtracting v ( t ) from both sides to give a new function: f ( m )= r g × m C d tanh t × r g × C d m ! v ( t ) We can now see that the answer to the problem posed by your boss is the value of m that makes the above function equal to zero. A simple and graphical approach for obtaining an estimate of the root of the equation f ( m )=0 is to make a plot of the function and observe where it crosses the x axis. This point, which represents the mass value for which f ( m )=0 ,p rov idesarough approximation of the root. Answer the following questions. •W r i t eaMATLABs c r ip tth a tp lo t sth efun c t ion f ( m ) versus m .A s sumead ragcoe fFc ien t of 0.35 kg/m, and for the bungee jumper to have a velocity of 40 m/s after 5s of free fall. •U s eana lgo r i thm i cm e thod toob t a inth eroo tau tom a t i c a l ly within your MATLAB code, that is you must not attempt to obtain the root via visual observation. Your code should achieve this by examining the vector containing the output values f ( m ) and by pinpointing the value of m for which f ( m ) is closest to zero. Use a fprintf statement to print this value. Your answer should be accurate to three decimal places. 2 https://www.coursehero.com/file/13145602/Assignment-1-Solution-Keypdf/ This study resource was shared via CourseHero.com
Show entire document
Sign up to view the entire interaction

congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a mol

a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae o

cing elit. Nam lacinia pulvinar t sus ante, dap a molestie consequat, ultrices ac o. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adi trices ac magna. pulvinar tortor nec facilisi

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents