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 Mfile for Eulers method as described in class and on pages of
the textbook for solving the differential equation
dv
dt g c
mv
this is on page is given below. As discussed in class, this numerical method
is obtained by approximating dv
dt at time ti by vtivti
titi which results in the computed
approximation
vtt vti
g c
mvti
ti ti
To create a MATLAB function Mfile, 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 Eulermcgtvtnn
print headings and initial conditions
fprintfvalues of t approximations vt
fprintfftfprintff
v
compute step size h
htntn;
set tv to the initial values
tt;
vv;
compute vt over n time steps using Eulers method
for i:n
vvgcmvh;
tth;
fprintfftfprintff
v
end
To save your Mfile, 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 local parameters in
the function Euler:
m is the mass of the falling object
c is the drag coefficient
g is the gravity constant
t is the initial time, v 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 t tn is divided
Thus, in the function Euler, the step size h tn tn is computed, and Eulers method
is used to compute an approximation to the solution vt of the differential equation at the
n points values of time
t h th th th t nh tn
For example, in order to use Euler to solve the problem given in Example on page
and to save your results in a file for printing, you could enter the following in the MATLAB
Command Window:
diary filename
Euler
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 kg c kgs and
initial conditions v on the time interval using time steps and for a
freefalling body on Venus where the gravitational constant is g ms
c Using the same parameters from Qb calculate the corresponding velocities using the
analytic solution. That is create a function for the formula,
vt gm
c e ct
m
and run it for t t : h : tn
d What is the terminal velocity of this freefalling body of mass 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
