MATLAB AND MATH
Name: ——————————— MATLAB ASSIGNMENT MATH 280 HYBRID – SPRING 2015 Return these sheets with your work. You need to show all your work ! All problems need to be solved using Matlab. Only typed solutions will be accepted. ONLY PRINTED VERSION WILL BE ACCEPTED ! (NO DIGITAL FORMATS !) Only two one-sided pages or one double-side page is allowed for each problem. Deadline for submission: Monday, May 4, 2015, 12:30pm. There will be no extensions ! Use at least four-digit accuracy for all the problems. Warning !!! Sharing your work or your solutions is strictly prohibited and will result in NO credit for this assignment. Problem 1. (10 points) Improved Euler method yn+1 = yn + h 2 [f(tn, yn) + f(tn + h, yn + hf(tn, yn))] , y0 = y(x0). Use Matlab for … end command and the improved Euler method to approximate the exact solution of y 0 − y 2 cos(πx) = 0, y(−2) = 1, on the interval [−2, 0] with h = 0.1 and h = 0.05. Provide the graphs of the exact and two approximate solutions on the interval [−2, 0] combined into a single plot. Also, compute the differences between the exact and two approximate solutions. What is the maximal error in the cases of h = 0.1? What is the maximal error in the case of h = 0.05? Hint: See Section 9 of the Matlab Primer. Problem 2. (10 points) Write a function file to solve the problem of an object projected vertically upward in the media offering resistance proportional to the square root of velocity (with k = 3, g = 9.81, and m = 4). Choose the positive direction of the velocity in the downward direction and the initial velocity v0 = −12. Additionally, find the time t0 such that v(t0) = 0. What is the velocity at t = 2? Hint: See Section 16 of the Matlab Primer. Problem 3. (4+3+3 points) For planets, the basic equation of motion is m d 2 r dt2 = F = − GmM r 2 ˆr, (M and m denote the masses of the Sun and of a planet, respectively.) (1) where G is a universal constant, r = (x, y, z) is a position vector, ˆr = r |r| , and |r| = p x 2 + y 2 + z 2 . Due to conservation of the momentum, the trajectories of planets are planar. Thus, in component form and the Cartesian coordinates system with the center of Sun located at the origin (0, 0) (with m = 1 and GM = 1), equation (1) has the form: d 2x dt2 = − x (x 2 + y 2 ) 3/2 , d 2 y dt2 = − y (x 2 + y 2 ) 3/2 . (2) Consider (2) with the initial conditions, x(0) = 0.5, dx dt (0) = vx(0) = 0, y(0) = 0, dy dt(0) = vy(0) = 1.63. (3) 1 2 MATLAB ASSIGNMENT MATH 280 HYBRID – SPRING 2015 (a) Write a suitable Matlab function to determine the orbit (plot of x versus y) of the planet described by (2)-(3). (b) Experiment with positive initial velocity in y-direction, vy(0), while keeping the initial position, x(0) = 0.5, y(0) = 0, and vx(0) = 0 fixed, until you obtain the one that produces a circular orbit. (c) For what choice(s) of vy(0) the orbit becomes an hyperbola. Hints: (i) Consider vector z = [z1, z2, z3, z4], where z1 = x, z2 = dx/dt, z3 = y, and z4 = dy/dt, and rewrite (2) as the system of four first order differential equations in the form dz dt = dz1 dt , dz2 dt , dz3 dt , dz4 dt = f(z), where f(z) = [f1(z), f2(z), f3(z), f4(z)]. (ii) Examples in Section 16 of the Matlab Primer provide all the needed ingredients to find a Matlab function that solves part (a). (iii) Increase tspan enough so that orbit closes upon itself. Problem 4 (10 points) Consider a system of four nonlinear differential equations describing the trajectory of a spinning tennis ball: x˙ = vx, v˙x = − CDαv · vx + ηCMαv · vz, z˙ = vz, v˙z = − g − CDαv · vz − ηCMαv · vx, (4) where v = √ x˙ 2 + ˙z 2 and α = (ρπd2 )/(8m). The parameter η = 1 for topspin lob and η = 0 for drag force only. Furthermore, CD = 0.508 + 1 22.053 + 4.196 v w 5/2 !2/5 CM = 1 2.022 + 0.981 v w . The quantity w = (d/2)|ω × (v/v)|, which can be thought as the projection of the equilateral velocity ω(d/2) of the spinning ball onto the velocity vector v is assumed constant and is provided. The initial conditions for (4) are of the form: x(0) = 0, z(0) = h, vx(0) = v0 cos θ, vz(0) = v0 sin θ. For the additional details look at http://www.csun.edu/~hcmth008/280/280_spinning_tennis_ball.pdf The acceleration due to gravity g = 9.81[m s−1 ], diameter of the tennis ball d = 0.063[m], its mass m = 0.05[kg], and air density ρ = 1.29[kg m−3 ]. For the initial data w = 23, h = 1.0, v0 = 20, θ = 23◦ , (a) Use Matlab ODE solver ode45 to write a Matlab function file that solves the initial value problem (4). (b) Use the output [x,z] to plot the trajectories of the motion for vacuum, no-spin, and with-spin cases. (c) Use Matlab interpolation procedure ynew = spline(x,y,xnew) combined with the fixed point iteration to find the flight time and maximal (horizontal) distance for vacuum, no-spin, and with-spin cases. Hint: See Sections 13, 14 and 16 of Matlab Primer at http://www.csun.edu/~hcmth008/matlab_tutorial/matlab_primer.pdf
