Difficulty: Hard EXERCISE6 (4 points) In this exercise, you will write a code th
ID: 639477 • Letter: D
Question
Difficulty: Hard EXERCISE6 (4 points) In this exercise, you will write a code that approximates in several points the solution to the initial value problem for the first-order differential equation by using Euler's Method. Given the initial value problem: We approximate the solution on the interval [x ,b] at N equidistant points x,x1x2,...,xN with x b. The step size h is the distance between the x-values and nh (n N) The set t yu, y,,..., yN represents the approximations of the solution y y(x) to the initial value problem at the points xix respectively. The recurs formulas used for the Euler's Method are: h x EX, n 1. N) Write a function in MATLAB function y difequ(x0, y0,b,N which will output the row vector y [y, y y of the desired approximations Consider y) exp(x3). Type the function difequ(x0, y0,b,N) in your diary file. Input the values: and run the function y difequ(x0,y0, b,N) to get the output vector yExplanation / Answer
function y = difequ(x0, y0, b, N)
y = zeros(1, N);
h= (b - x0)/N;
y(1) = y0 + h*x0*x0;
for i = 2 : N
y(i) = y(i-1) + h*(x0 + (i-1)*h)*(x0 + (i-1)*h);
end
end
x0=0;
y0=1;
b=1;
N=6;
y = difequ(x0, y0, b, N)
--------------------------------------------
OUTPUT
y =
1.0000 1.0046 1.0231 1.0648 1.1389 1.2546