In: Advanced Math
Now that we have seen Euler in action, let's return to examining the content of the M-File Euler.m. We have already explained the first line, where we defined the parameters our function takes. To see the meaning behind the third and fourth lines, type:
>> x = zeros(10,1); y = zeros(10,1); [x,y]
Thus we can see that the third and fourth lines of our M-File zero out the contents of our arrays x and y before we begin. Now, you'll continue examining our code.
Question: In your Word document, briefly explain what is happening in each remaining line of the M-File Euler.m.
The M-File is:
function [x,y] = Euler(h, x0, y0, interval_length, func) nsteps = floor(interval_length/h) + 1; x = zeros(nsteps,1); y = zeros(nsteps,1); x(1) = x0; y(1) = y0; for i=2:nsteps y(i) = y(i-1) + h* func(x(i-1), y(i-1)); x(i) = x(i-1) + h; end