In: Computer Science
Program a calculator or computer to use Euler's method to compute y(1), where y(x) is the solution of the given initial-value problem. (Give all answers to four decimal places.)
dy/dx+ 3x2y = 12x2,
y(0) = 5
| h = 1 | y(1) = |
| h = 0.1 | y(1) = |
| h = 0.01 | y(1) = |
| h = 0.001 | y(1) = |
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
clc
clear all
close all
f=@(x,y) 12*x^2-3*x^2*y;
for h=[1,0.1,0.01,0.001]
[x,y]=eulerSystem(f,[0,1],5,h);
fprintf('For h=%f, y(1)=%.4f\n',h,y(end));
end
function [t,y]=eulerSystem(Func,Tspan,Y0,h)
t0=Tspan(1);
tf=Tspan(2);
N=(tf-t0)/h;
y=zeros(length(Y0),N+1);
y(:,1)=Y0;
t=t0:h:tf;
for i=1:N
y(:,i+1)=y(:,i)+h*Func(t(i),y(:,i));
end
end

For h=1.000000, y(1)=5.0000
For h=0.100000, y(1)=4.3928
For h=0.010000, y(1)=4.3701
For h=0.001000, y(1)=4.3681
Kindly revert for any queries
Thanks.