Question: A MATLAB function M - file for Euler s method ( as described in class and on pages 1 7 - 1 9 of the

A MATLAB function M-file for Eulers method (as described in class and on pages 17-19 of
the textbook) for solving the differential equation
dv
dt = g c
mv
(this is (1.9) on page 14) is given below. As discussed in class, this numerical method
is obtained by approximating dv
dt at time ti by v(ti+1)v(ti)
ti+1ti , which results in the computed
approximation
v(tt+1)= v(ti)+
[
g c
mv(ti)
]
(ti+1 ti).
1
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 Eulers method. Enter the following, (Note - dont copy and paste
as the quotes might not work). Statements starting with % are comments, documenting the
MATLAB code.
function Euler(m,c,g,t0,v0,tn,n)
% print headings and initial conditions
fprintf(values of t approximations v(t)
)
fprintf(%8.3f,t0),fprintf(%19.4f
,v0)
% compute step size h
h=(tn-t0)/n;
% set t,v to the initial values
t=t0;
v=v0;
% compute v(t) over n time steps using Eulers method
for i=1:n
v=v+(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
t0 is the initial time, v0 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 [t0, tn] is divided
Thus, in the function Euler, the step size h =(tn t0)/n is computed, and Eulers method
is used to compute an approximation to the solution v(t) of the differential equation at the
2
n points (values of time)
t0+ h, t0+2h, t0+3h, t0+4h,..., t0+ nh = tn.
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 working copy of the Euler function using MATLAB or Python MATLAB.
Upload a copy of your function to Crowdmark.
(b) Use Euler to solve the differential equation using m =75.3 kg, c =13.1 kg/s and
initial conditions v(0)=0 on the time interval [0,16] using 40 time steps and for a
free-falling body on Venus where the gravitational constant is g =8.87 m/s2.
(c) Using the same parameters from Q1(b) calculate the corresponding velocities using the
analytic solution. That is, create a function for the formula,
v(t)= gm
c (1 e ct
m )(1)
and run it for t =[t0 : h : tn].
(d) What is the terminal velocity of this free-falling body of mass 75.3 kg on Venus? (You
may approximate this roughly with experimental results from your function or solve it
analytically.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!