hw2_solns

# hw2_solns - Mathematics of Engineering - ME17 Spring 2007...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Mathematics of Engineering - ME17 Spring 2007 Homework #2 - Solutions 1. (15 points total) (a) (10 pts) We need to write a Matlab program in which we take t = 0 : 0.1 : 3 and x(t) = v0x t + x0 , 1 2 y(t) = ay t + v0y t + y0 2 to find matrices with the same size as the t matrix and with the corresponding instantaneous values of x and y. The following m.file finds these matrices and plots x vs. t, y vs. t, and y vs. x. % % % Problem 1( a ) % % % t = 0 : 0.1 : 3; x0 = 0 ; y0 = 1 0 ; v0x = 5 ; v0y = 1 0 ; ax = 0 ; ay = -10; % t matrix % i n i t i a l positions % initial velocities % gravitational acceleration x = v0x t + x0 ; % E q u a t i o n s o f motion y = ( 1 / 2 ) ay t . ^ 2 + v0y t + y0 ; % P l o t commands hold on ; subplot ( 3 , 1 , 1 ) ; plot ( t , x ) xlabel ( ' time ( s ) ' ) ; ylabel ( ' x (m) ' ) ; subplot ( 3 , 1 , 2 ) ; plot ( t , y ) xlabel ( ' time ( s ) ' ) ; ylabel ( ' y (m) ' ) ; subplot ( 3 , 1 , 3 ) ; plot ( x , y ) xlabel ( ' x (m) ' ) ; ylabel ( ' y (m) ' ) ; % h o l d s c u r r e n t p l o t and a x i s % x-a x i s l a b e l % y-a x i s l a b e l 1 20 x (m) 10 0 0 0.5 1 1.5 time (s) 2 2.5 3 20 y (m) 0 -20 0 0.5 1 1.5 time (s) 2 2.5 3 20 y (m) 0 -20 0 5 x (m) 10 15 Figure 1: Solution to problem 1a. (b) (5 pts) To determine the approximate values of t and x at y = 0, we need to find the element of the y matrix which is closest to zero, then viewing the corresponding elements of the t and x matrices. For this problem, y(28) = 0.55 is closest to zero, therefore: t(28) = 13.5, x(28) = 2.7. 2 2. (10 points total) Using the following Matlab commands: plot(x,y) semilogx(x,y) semilogy(x,y) loglog(x,y) we need to plot the data x = [1 6 11 16 21 26 31 36 41 46] y = [10 360 1210 2560 4410 6760 9610 12960 16810 21160]. % % % Problem 2 % % % x = [ 1 6 11 16 21 26 31 36 41 4 6 ] ; y = [ 1 0 360 1210 2560 4410 6760 9610 12960 16810 2 1 1 6 0 ] ; % P l o t commands hold on ; figure (1) plot ( x , y ) t i t l e ( ' Linear Plot ' ) ; xlabel ( ' x ' ) ; ylabel ( ' y ' ) ; figure (2) semilogx ( x , y ) ; t i t l e ( ' semilogx Plot ' ) ; xlabel ( ' l o g x ' ) ; ylabel ( ' y ' ) ; figure (3) semilogy ( x , y ) ; t i t l e ( ' semilogy Plot ' ) ; xlabel ( ' x ' ) ; ylabel ( ' l o g y ' ) ; figure (4) loglog ( x , y ) ; t i t l e ( ' l o g l o g Plot ' ) ; xlabel ( ' l o g x ' ) ; ylabel ( ' l o g y ' ) ; % t i t l e of plot % x-a x i s l a b e l % y-a x i s l a b e l 3 This m.file gives us the following plots: 2.5 x 10 4 Linear Plot 2.5 x 10 4 semilogx Plot 2 2 1.5 y y 1 1.5 1 0.5 0.5 0 0 5 10 15 20 25 x 30 35 40 45 50 0 0 10 10 log x 1 10 2 10 5 semilogy Plot 10 5 loglog Plot 10 4 10 4 log y 10 3 log y 10 3 10 2 10 2 10 1 0 5 10 15 20 25 x 30 35 40 45 50 10 0 10 1 10 log x 1 10 2 4 For this problem, the `loglog(x,y)' plot gives you a straight line. The equation of a straight line is y = mx + b, where m is the slope and b is the y-intercept. Now we need to pick two points from Figure 2 in order to calculate the slope of the line. loglog Plot 10 5 10 4 log y 10 3 10 2 10 0 10 1 10 log x 1 10 2 Figure 2: The `loglog' plot. Here we see that when log(x1 ) = 0, log(y1 ) = 1 and when log(x2 ) = 1, log(y2 ) = 3 (notice that these correspond to the exponents of each of the points as discussed in class). Therefore, the slope of this line is: slope = log(y2 ) - log(y1 ) 3-1 = = 2. log(x2 ) - log(x1 ) 1-0 To find the y-intercept, we know that the line crosses the y axis at 101 , therefore b = 1 corresponding to a exponent of 1. Therefore, the equation of the line is: log(y) = 2 log(x) + 1, rearranging give us y = 10x2 . 5 (1) 3. (10 points total) (a) (1 pts) The probability of having six attacks in one year can be found using Matlab as follows: % % % Problem 3( a ) % % % m = 3; k = 6; % a v e r a g e number o f o c c u r e n c e s i n a g i v e n time i n t e r v a l % number o f a t t a c k s % p r o b a b i l i t y o f h a v i n g k a t t a c k s i n one y e a r a = exp(-m) m^k/ f a c t o r i a l ( k ) ; disp ( a ) ; % displays the value of a From this m.file, the probability of having six attacks in one year is 0.0504. (b) (1 pts) The probability of having zero attacks in one year can be found using Matlab as follows: % % % Problem 3( b ) % % % m = 3; k = 0; % a v e r a g e number o f o c c u r e n c e s i n a g i v e n time i n t e r v a l % number o f a t t a c k s % p r o b a b i l i t y o f h a v i n g k a t t a c k s i n one y e a r a = exp(-m) m^k/ f a c t o r i a l ( k ) ; disp ( a ) ; % displays the value of a From this m.file, the probability of having six attacks in one year is 0.0498. 6 (c) (1 pts) The approximation to the finite sum given by 10 p(k) k=0 can be found using Matlab as follows: % % % Problem 3( c ) % % % m = 3; k = 0 : 10; x = [1 1:10]; f = cumprod( x ) ; % a p p r o x i m a t i o n t o f i n i t e sum a = sum( exp(-m) m. ^ k . / f ) ; disp ( a ) ; % displays the value of a % a v e r a g e number o f o c c u r e n c e s i n a g i v e n time i n t e r v a l % number o f a t t a c k s From this m.file, the approximation is 0.9997. (d) (1 pts) The approximation to the finite sum given by 10 kp(k) k=0 can be found using Matlab as follows: % % % Problem 3( d ) % % % m = 3; k = 0 : 10; x = [1 1:10]; f = cumprod( x ) ; % a p p r o x i m a t i o n t o f i n i t e sum a = sum( k . exp(-m) . m. ^ k . / f ) ; disp ( a ) ; % displays the value of a % a v e r a g e number o f o c c u r e n c e s i n a g i v e n time i n t e r v a l % number o f a t t a c k s From this m.file, the approximation is 2.9967. 7 ...
View Full Document

Ask a homework question - tutors are online