%%%%%%%%%%%% Solution of (a) and (b) by Euler
clc;
clear all;
f=@(t,y) 3*t^2-y;
a=0;% starting point
b=1; %ending point
h=0.05; % step length
n=(b-a)/h;
y(1)=1; % Initial condition
t=a:h:b;
%Euler formula
for i=1:n
y(i+1)=y(i)+h*f(t(i),y(i));
end
disp('Approximation solution')
for i=1:n+1
fprintf('y(%f)= \t %10f \n',t(i),y(i))
end
%True solution
for i=1:n+1
y_ex(i)=3*t(i)^2-6*t(i)-5*exp(-t(i))+6;
end
plot(t,y,'-r*')
hold on
plot(t,y_ex,'-m')
xlabel('t','fontsize',15)
ylabel('y','fontsize',15)
legend('Euler method','True solution')
disp('________________________________________________________________________________')
disp('t Euler solution True solution ')
disp('________________________________________________________________________________')
for i=1:n+1
fprintf('%f \t %10f \t %15f \n',t(i),y(i), y_ex(i))
end
Approximation solution
y(0.000000)= 1.000000
y(0.050000)= 0.950000
y(0.100000)= 0.902875
y(0.150000)= 0.859231
y(0.200000)= 0.819645
y(0.250000)= 0.784662
y(0.300000)= 0.754804
y(0.350000)= 0.730564
y(0.400000)= 0.712411
y(0.450000)= 0.700790
y(0.500000)= 0.696126
y(0.550000)= 0.698820
y(0.600000)= 0.709254
y(0.650000)= 0.727791
y(0.700000)= 0.754776
y(0.750000)= 0.790538
y(0.800000)= 0.835386
y(0.850000)= 0.889616
y(0.900000)= 0.953511
y(0.950000)= 1.027335
y(1.000000)= 1.111343
________________________________________________________________________________
t Euler solution True solution
________________________________________________________________________________
0.000000 1.000000 1.000000
0.050000 0.950000 0.951353
0.100000 0.902875 0.905813
0.150000 0.859231 0.863960
0.200000 0.819645 0.826346
0.250000 0.784662 0.793496
0.300000 0.754804 0.765909
0.350000 0.730564 0.744060
0.400000 0.712411 0.728400
0.450000 0.700790 0.719359
0.500000 0.696126 0.717347
0.550000 0.698820 0.722751
0.600000 0.709254 0.735942
0.650000 0.727791 0.757271
0.700000 0.754776 0.787073
0.750000 0.790538 0.825667
0.800000 0.835386 0.873355
0.850000 0.889616 0.930425
0.900000 0.953511 0.997152
0.950000 1.027335 1.073795
1.000000 1.111343 1.160603
>>
%%%%%%%%%%%% Solution of (a) and (b) by Rk2
clc;
clear all;
f=@(t,y) 3*t^2-y;
a=0;% starting point
b=1; %ending point
h=0.05; % step length
n=(b-a)/h;
y(1)=1; % Initial condition
t=a:h:b;
for i=1:n
m1=h*f(t(i),y(i));
m2=h*f(t(i+1),y(i)+m1);
y(i+1)=y(i)+(m1+m2)/2;
end
disp('Approximation solution by Rk2')
for i=1:n+1
fprintf('y(%f)= \t %10f \n',t(i),y(i))
end
%True solution
for i=1:n+1
y_ex(i)=3*t(i)^2-6*t(i)-5*exp(-t(i))+6;
end
plot(t,y,'-r*')
hold on
plot(t,y_ex,'-m')
xlabel('t','fontsize',15)
ylabel('y','fontsize',15)
legend('RK2 method','True solution')
disp('________________________________________________________________________________')
disp('t RK2 solution True solution ')
disp('________________________________________________________________________________')
for i=1:n+1
fprintf('%f \t %10f \t %15f \n',t(i),y(i), y_ex(i))
end
Approximation solution by Rk2
y(0.000000)= 1.000000
y(0.050000)= 0.951438
y(0.100000)= 0.905983
y(0.150000)= 0.864216
y(0.200000)= 0.826689
y(0.250000)= 0.793925
y(0.300000)= 0.766425
y(0.350000)= 0.744661
y(0.400000)= 0.729087
y(0.450000)= 0.720132
y(0.500000)= 0.718204
y(0.550000)= 0.723691
y(0.600000)= 0.736964
y(0.650000)= 0.758375
y(0.700000)= 0.788257
y(0.750000)= 0.826930
y(0.800000)= 0.874695
y(0.850000)= 0.931841
y(0.900000)= 0.998642
y(0.950000)= 1.075358
y(1.000000)= 1.162238
________________________________________________________________________________
t RK2 solution True solution
________________________________________________________________________________
0.000000 1.000000 1.000000
0.050000 0.951438 0.951353
0.100000 0.905983 0.905813
0.150000 0.864216 0.863960
0.200000 0.826689 0.826346
0.250000 0.793925 0.793496
0.300000 0.766425 0.765909
0.350000 0.744661 0.744060
0.400000 0.729087 0.728400
0.450000 0.720132 0.719359
0.500000 0.718204 0.717347
0.550000 0.723691 0.722751
0.600000 0.736964 0.735942
0.650000 0.758375 0.757271
0.700000 0.788257 0.787073
0.750000 0.826930 0.825667
0.800000 0.874695 0.873355
0.850000 0.931841 0.930425
0.900000 0.998642 0.997152
0.950000 1.075358 1.073795
1.000000 1.162238 1.160603
>>
C)
clc;
clear all;
f=@(t,y) 3*t^2-y;
a=0;% starting point
b=1; %ending point
h=0.05; % step length
n=(b-a)/h;
y(1)=1; % Initial condition
t=a:h:b;
%Euler formula
for i=1:n
y(i+1)=y(i)+h*f(t(i),y(i));
end
y1(1)=1
for i=1:n
m1=h*f(t(i),y1(i));
m2=h*f(t(i+1),y1(i)+m1);
y1(i+1)=y1(i)+(m1+m2)/2;
end
%True solution
for i=1:n+1
y_ex(i)=3*t(i)^2-6*t(i)-5*exp(-t(i))+6;
end
for i=1:n+1
L(i)= abs(y(i)-y_ex(i));
end
for i=1:n+1
L1(i)= abs(y1(i)-y_ex(i));
end
plot(t,L,'-r*')
hold on
plot(t,L1,'-m')
xlabel('t','fontsize',15)
ylabel('LTE','fontsize',15)
legend('Euler','Rk2')
Complete using MatLab 1. Consider the following initial value problem 3t2-y, y(0) = 1 Using Euler's...
VOX) + Consider the initial value problem y' - 2x - 3y + 1, y(1) 9. The analytic solution is 1 2 74 + -3x - 1) 3 9 (a) Find a formula involving c and h for the local truncation error in the nth step if Euler's method is used. (b) Find a bound for the local truncation error in each step ith-0.1 is used to approximate y(1.5). (Proceed as in Example 1 of Section 6.1.) (c) Approximate y(1.5)...
Consider the initial-value problem y' = 2x - 3y + 1, y(1) = 9. The analytic solution is 1 2 74 -X + e-3(x - 1) 9 (a) Find a formula involving c and h for the local truncation error in the nth step if Euler's method is used. (b) Find a bound for the local truncation error in each step if h = 0.1 is used to approximate y(1.5). (Proceed as in Example 1 of Section 6.1.) (c) Approximate...
Consider the initial-value problem y' = 2x – 3y + 1, y(1) = 9. The analytic solution is 1 2 74 e-3(x - 1). 9 3 9 (a) Find a formula involving c and h for the local truncation error in the nth step if Euler's method is used. 372²e -3(0-1) (b) Find a bound for the local truncation error in each step if h = 0.1 is used to approximate y(1.5). (Proceed as in Example 1 of Section 6.1.)...
please show all steps and equations used, please write
neatly.
Problem 16. Given the Runge-Kutta method for the initial value problem y' = f(t,y) for a
Problem Thre: 125 points) Consider the following initial value problem: dy-2y+ t The y(0) -1 ea dt ical solution of the differential equation is: y(O)(2-2t+3e-2+1)y fr exoc the differential equation numerically over the interval 0 s i s 2.0 and a step size h At 0.5.A Apply the following Runge-Kutta methods for each of the step. (show your calculations) i. [0.0 0.5: Euler method ii. [0.5 1.0]: Heun method. ii. [1.0 1.5): Midpoint method. iv. [1.5 2.0): 4h RK method...
step Consider the IVP y = 1 + y?, y(0) = 0 a. Use the Runge-Kutta Method with step size 0.1 to approximate y(0.2) b. Find the error between the analytic solution and the approximate solution at each step
///MATLAB/// Consider the differential equation over the
interval [0,4] with initial condition y(0)=0.
3. Consider the differential equation n y' = (t3 - t2 -7t - 5)e over the interval [0,4 with initial condition y(0) = 0. (a) Plot the approximate solutions obtained using the methods of Euler, midpoint and the classic fourth order Runge Kutta with n 40 superimposed over the exact solution in the same figure. To plot multiple curves in the same figure, make use of the...
MATLAB HELP 3. Consider the equation y′ = y2 − 3x, where y(0) =
1. USE THE EULER AND RUNGE-KUTTA APPROXIMATION SCRIPTS
PROVIDED IN THE PICTURES
a. Use a Euler approximation with a step size of 0.25 to
approximate y(2).
b. Use a Runge-Kutta approximation with a step size of 0.25 to
approximate y(2).
c. Graph both approximation functions in the same window as a
slope field for the differential equation.
d. Find a formula for the actual solution (not...
Consider the following initial value problem у(0) — 0. у%3D х+ у, (i) Solve the differential equation above in tabular form with h= 0.2 to approximate the solution at x=1 by using Euler's method. Give your answer accurate to 4 decimal places. Given the exact solution of the differential equation above is y= e-x-1. Calculate (ii) all the error and percentage of relative error between the exact and the approximate y values for each of values in (i) 0.2 0.4...
YOUR TEACHER Consider the initial-value problem y = (x + y - 1)?.Y(0) - 2. Use the improved Euler's method with h = 0.1 and h = 0.05 to obtain approximate values of the solution at x = 0.5. At each step compare the approximate value with the actual value of the analytic solution (Round your answers to four decimal places.) h 0.1 Y(0.5) h 0.05 Y(0.5) actual value Y(0.5) = Need Help? Tuto Tutor