Question: Euler Function Create a file called euler.m that contains a function of the form function [ t , y ] = euler ( f ,
Euler Function
Create a file called euler.m that contains a function of the form
function eulerf t y tn N
This function should accept
f : an anonymous function help on anonymous functions of and that describes the differential equation,
such that
use @ to define it but that comes later
t y: the initial condition
tn: the value where the approximation should end
N : the number of steps used to get from to to tn
It should return
t: an array containing values, evenly spaced from to to tn
y: an array representing the solution to the differential equation the final value should be
Start by using to tn and N to calculate the step size h then use that to generate the t array. Once you have
that, initialize the y array I usually start by creating an array of zeros of the right size
Then use a for loop to fill in the values in the y array, using the formula for Euler's method inside the loop,
calculate the value of the derivative at that point and use that to get the next value
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
