%%Matlab code shooting method using RK4 for 2nd order
differential equation
clear all
close all
%Program for shooting method
f=@(x,y1,y2)
y2;
%function (i)
g=@(x,y1,y2)
y1^2-(x./(1+x));
%function (ii)
%all guesses for y2(1) using shooting method
a_ini=[0:.005:10]; y1_end=1;
for ii=1:length(a_ini)
x(1)=0;y1(1)=0;y2(1)=a_ini(ii); %initial
conditions
h=0.01;
%step length
x_in=x(1);
%Initial x
x_max=1;
%Final x
n=(x_max-x_in)/h; %number of steps
%Runge Kutta 4 iterations
for i=1:n
k0=h*f(x(i),y1(i),y2(i));
l0=h*g(x(i),y1(i),y2(i));
k1=h*f(x(i)+(1/2)*h,y1(i)+(1/2)*k0,y2(i)+(1/2)*l0);
l1=h*g(x(i)+(1/2)*h,y1(i)+(1/2)*k0,y2(i)+(1/2)*l0);
k2=h*f(x(i)+(1/2)*h,y1(i)+(1/2)*k1,y2(i)+(1/2)*l1);
l2=h*g(x(i)+(1/2)*h,y1(i)+(1/2)*k1,y2(i)+(1/2)*l1);
k3=h*f(x(i)+h,y1(i)+k2,y2(i)+l2);
l3=h*g(x(i)+h,y1(i)+k2,y2(i)+l2);
x(i+1)=x_in+i*h;
y1(i+1)=double(y1(i)+(1/6)*(k0+2*k1+2*k2+k3));
y2(i+1)=double(y2(i)+(1/6)*(l0+2*l1+2*l2+l3));
end
yy1(ii)=y1(end);
end
p = interp1(yy1,a_ini,y1_end);
fprintf('\tThe value of U2(0) using shooting method is %f.\n',p);
%solution using value of y2(1)
x(1)=0;y1(1)=0;y2(1)=p; %initial
conditions
h=0.01;
%step length
x_in=x(1); %Initial
x
x_max=1;
%Final x
n=(x_max-x_in)/h; %number of steps
%Runge Kutta 4 iterations
for i=1:n
k0=h*f(x(i),y1(i),y2(i));
l0=h*g(x(i),y1(i),y2(i));
k1=h*f(x(i)+(1/2)*h,y1(i)+(1/2)*k0,y2(i)+(1/2)*l0);
l1=h*g(x(i)+(1/2)*h,y1(i)+(1/2)*k0,y2(i)+(1/2)*l0);
k2=h*f(x(i)+(1/2)*h,y1(i)+(1/2)*k1,y2(i)+(1/2)*l1);
l2=h*g(x(i)+(1/2)*h,y1(i)+(1/2)*k1,y2(i)+(1/2)*l1);
k3=h*f(x(i)+h,y1(i)+k2,y2(i)+l2);
l3=h*g(x(i)+h,y1(i)+k2,y2(i)+l2);
x(i+1)=x_in+i*h;
y1(i+1)=double(y1(i)+(1/6)*(k0+2*k1+2*k2+k3));
y2(i+1)=double(y2(i)+(1/6)*(l0+2*l1+2*l2+l3));
end
%plotting the solution
figure(2)
plot(x,y1)
title('Plotting of u(x) using shooting
method')
xlabel('x')
ylabel('u(x)')
ps=find(x==0.5);
fprintf('\t The approximate value for U(%f) is
%f.\n',x(ps),y1(ps))
%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%%
2. Use an RK4 shooting method with a step size of h - 0.01 to find the unique negative solution t...
Problem 1 Use Euler's method with step size h = 0.5 to approximate the solution of the IVP. 2 dy ev dt t 1-t-2, y(1) = 0. Problem 2 Consider the IVP: dy dt (a) Use Euler's method with step size h0.25 to approximate y(0.5) b) Find the exact solution of the IV P c) Find the maximum error in approximating y(0.5) by y2 (d) Calculate the actual absolute error in approximating y(0.5) by /2.
Problem 1 Use Euler's method...
Consider the following boundary-value problem$$ y^{\prime \prime}-2 y^{\prime}+y=x^{2}-1, y(0)=2, \quad y(1)=4 $$Apply the linear shooting method and the Euler method with step size of \(\frac{1}{3}\) to marks) approximate the solution of the problem.
Given the following non-linear boundary value problem
Use the shooting method to approximate solution
Use finite difference to approximate solution
Plot the approximate solutions together with the exact solution
y(t) = 1/3t2 and discuss your results
with both methods
(a) Use Euler's Method with a step size h = 0.1 to approximate y(0.0), y(0.1), y(0.2), y(0.3), y(0.4), y(0.5) where y(x) is the solution of the initial-value problem ay = - y2 cos x, y(0) = 1. (b) Find and compute the exact value of y(0.5). dx
Use Euler's method with step size h = 0.2 to approximate the solution to the initial value problem at the points x = 4.2, 4.4, 4.6, and 4.8. y = {(V2+y),y(4)=1 Complete the table using Euler's method. xn Euler's Method 4.2 4.4 n 1 2 2 3 4.6 4 4.8 (Round to two decimal places as needed.)
Consider the initial-value problem yl =0.3y y(3) = 0.2 (a) Use Euler's method to estimate y (-2with step size h 0.5 Give your approximation for y (-2)with a precision of ±0.01 y(2) Number (b) Use Euler's method to estimate y (-2)with step size h = 0.25 Give your approximation for y (-2)with a precision of ±0.01 y (-2) Number
Consider the initial-value problem yl =0.3y y(3) = 0.2 (a) Use Euler's method to estimate y (-2with step size h 0.5...
solution with matlab only please
Problem 2: Use the shooting method to solve d T _-10-7 (T +273)' + 4(150-7): 0 With the boundary conditions T(O)- 200 and T(0.5)-100
Problem 2: Use the shooting method to solve d T _-10-7 (T +273)' + 4(150-7): 0 With the boundary conditions T(O)- 200 and T(0.5)-100
dy Use Euler's Method with step size h = 0.2 to approximate y(1), where y(x) is the solution of the initial-value problem + 3x2y = 6x2, dx y(0) = 3.
Need help with this MATLAB problem:
Using the fourth order Runge-Kutta method (KK4 to solve a first order initial value problem NOTE: This assignment is to be completed using MATLAB, and your final results including the corresponding M- iles shonma ac Given the first order initial value problem with h-time step size (i.e. ti = to + ih), then the following formula computes an approximate solution to (): i vit), where y(ti) - true value (ezact solution), (t)-f(t, v), vto)...
4. (a) (7 points) Use Euler's method with step size h = 0.5 to estimate the value at t = 1 of the solution to the initial value problem =t+y and y(0) = 1. dy