Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question #1 - 10 marks. A MATLAB function M-file for Euler's method as described in class and on pages 17-19 of the textbook) for solving

image text in transcribedimage text in transcribedimage text in transcribed

Question #1 - 10 marks. A MATLAB function M-file for Euler's method as described in class and on pages 17-19 of the textbook) for solving the differential equation (this is (1.9) on page 14) is given below. As discussed in class, this numerical method is obtained by approximating at time t, by utica)-(41), which results in the computed approximation v(te+1) = v(t:) + [g- molts)) (t3+1 t). To create a MATLAB function M-file, either type edit in the Command Window or select HOME New + Script or select HOME New Function (the latter gives you a template for creating a function). Each of these options will open a new window (an Editor window) in which to type in the MATLAB statements for Euler's method. Enter the following. Statements starting with % are comments, documenting the MATLAB code. function Euler(m,c,g,to,vo, tn,n) % print headings and initial conditions fprintf('values of t approximations v(t) ') fprintf("%8.3f',to), fprintf("%19.4f ',vo) % compute step size h h=(tn-to); % set t,v to the initial values t=t0; v=v0; % compute v(t) over n time steps using Euler's method for i=1:n v=y+(g-c/m*v)*h; t=t+h; fprintf("%8.3f',t),fprintf("%19.4f ',v) end To save your M-file, select EDITOR Save + Save As... At the top of this window, it should say File name: Euler.m Save as type: MATLAB files (*.m) Select Save to save your file, and close the Editor window. In order to use the above function, you must specify values for the 7 local parameters in the function Euler: m is the mass of the falling object c is the drag coefficient g is the gravity constant to is the initial time, vo is the initial velocity tn is the final time at which the velocity is to be computed n is the number of time steps into which to tnl is divided Thus, in the function Euler, the step size h= (tr-to) is computed, and Euler's method is used to compute an approximation to the solution v(t) of the differential equation at the n points (values of time) to +h, to + 2h, to +3h, to +4h, ..., to +nh = tr For example, in order to use Euler to solve the problem given in Example 1.2 on page 17 and to save your results in a file for printing, you could enter the following in the MATLAB Command Window): diary filename Euler ( 68.1 , 12.5, 9.81, 0, 0, 12, 6) {the desired results should appear here) diary off (a) Create a copy of the MATLAB function Euler in your installation of MATLAB. Modify the function so that it creates and returns two matrices, one containing the times used in the calculations and one for the resulting velocities. Note, we index matrices in MATLAB with round brackets and we start indexing at 1 NOT O. That is, if t is a vector representing the times, then t(1) should contain time to and t(2) should contain time t1 = to +h, etc. The final matrices should be t = to ti ...tr and v= u(to) vti) ... v(tr)]. DELIVERABLES: A copy of the M-FILE in your pdf. (b) Use Euler to solve the differential equation using m = 73.5 kg, c = 13.1 kg/s and initial conditions v(0) = 0 on the time interval (0.16] using 80 time steps and for a free-falling body on Mars where the gravitational constant is g=3.71. DELIVERABLES: The function call to Euler and the resulting output. (c) Using the same parameters from Q1(b) solve the differential equation analytically in MATLAB. That is, create a function for the formula, v(t) = 9m (1-2) (1) and run it for t = [t0:h: tn). DELIVERABLES: The function, the call and the results. (d) Plot the results from Q1(b) and Q1(c) together to compare. DELIVERABLES: The commands and resulting plot. (e) What is the terminal velocity of this free-falling body of mass 73.5 kg? (You may approximate this roughly with experimental results from your function or solve it analytically.) DELIVERABLES: MATLAB output if using MATLAB or your analytic solution

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

Recommended Textbook for

More Books

Students also viewed these Databases questions