Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

dy/dx = x - y, y(0) = 2 A) Write a Matlab which approximate the solution to the

ID: 3110659 • Letter: D

Question

dy/dx = x - y, y(0) = 2 A) Write a Matlab which approximate the solution to the initial value problem. B) Use the Code from question A) with step size h = 0.1 to approximate y(2). C) Repeat question B) for the step size A = .06. D) Repeat question B) for the step size h = .005. E) Verify phi(x) = Ce^-x + x - 1, is a solution to the first order differential equation. F) Plot the solutions of B), C), D), and E) on the same coordinate axis and compare if Euler Method is a good approximate to the first-order differential equation.

Explanation / Answer

clc;

clear t

clear y

f=@(x,y) x-y

a=0;

b=2;

h=0.2;

y0=2;

N=(b-a)/h;

t(1)=a;

y(1)=y0;

for n=1:N

t(n+1)=t(n)+h;

y(n+1)=y(n)+h*f(t(n),y(n));

end

t'

y'

(b) Changing the value of h to 0.1 y(2)=1.3647

(c) Changing the value of h to 0.05 y(2)= 1.3855

(d) Changing the value of h to 0.005 y(2)=1.4040