Set up and solve a boundary value problem using the shooting method using Matlab
%%Matlab code using RK4 for 2nd order differential
equation
clear all
close all
%Program for RK4 for question a..
f=@(x,y1,y2)
y2;
%function (i)
g=@(x,y1,y2)
25;
%function (ii)
%all guesses for p using shooting method
zg=linspace(-200,100,1000);
for ii=1:length(zg)
x(1)=0;y1(1)=40;y2(1)=zg(ii); %initial
conditions
h=0.01;
%step length
x_in=x(1);
%Initial x
x_max=10;
%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,zg,200);
clear x; clear y1; clear y2
%solution using value of p
x(1)=0;y1(1)=40;y2(1)=p; %initial
conditions
h=0.01;
%step length
x_in=x(1);
%Initial x
x_max=10;
%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
figure(1)
%plotting the solution
plot(x,y1)
title('Plotting of TA(x) using shooting
method')
xlabel('x')
ylabel('TA(x)')
clear x; clear y1; clear y2;
%Program for RK4 for question b..
f=@(x,y1,y2)
y2;
%function (i)
g=@(x,y1,y2)
0.12.*x.^3-2.4.*x.^2+12.*x;
%all guesses for p using shooting method
zg=linspace(-200,100,1000);
for ii=1:length(zg)
x(1)=0;y1(1)=40;y2(1)=zg(ii); %initial
conditions
h=0.01;
%step length
x_in=x(1);
%Initial x
x_max=10;
%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,zg,200);
clear x; clear y1; clear y2
%solution using value of p
x(1)=0;y1(1)=40;y2(1)=p; %initial
conditions
h=0.01;
%step length
x_in=x(1);
%Initial x
x_max=10;
%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
figure(2)
%plotting the solution
plot(x,y1)
title('Plotting of TB(x) using shooting
method')
xlabel('x')
ylabel('TB(x)')
%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%
Set up and solve a boundary value problem using the shooting method using Matlab
Please provide the program in Matlab. Question 12) Solve the boundary value problem using a program/script that applied the shooting method. (t) + y()-8 with the boundary conditions of y(0)-0 and y(10-0. Use ΔΧ-1. Plot on the same axis your solution and the exact solution dt2 t 4 4 dt Question 12) Solve the boundary value problem using a program/script that applied the shooting method. (t) + y()-8 with the boundary conditions of y(0)-0 and y(10-0. Use ΔΧ-1. Plot on...
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
! Required information An insulated heated rod with a uniform heat source can be modeled with the Poisson equation as given below. de = -f(x) Given: A heat source fx) = 25°C/m2 and the boundary conditions Tlx = 0) = 40 °C and Tlx = 10) = 200 °C Solve the ODE using the shooting method. (Round the final answer to the nearest integer.) The temperature distribution at x = 4 is K. Use the fourth-order RK method using a...
Question 19 Using the shooting method for the following second-order differential equation governing the boundary value problem G.E: + EA () 9 + - =D () 2 € (0,L] B.C's:u (0) = 0 and EA (2) --=F. An appropriate algebraic equation to use in the finite difference solution of the boundary value problem posed in question 24 is -Post A)u(L) - (L+Ax) EAL) F. 201 B) Su (L) - u(L - Ax) + 4u (L + A2) EAL C) (L)...
Could anyone please help me? Thank you very much. (d) Describe the strategy you would use to solve the general BVP 4 pts using the shooting method. Describe the functions you need to write, what you need to guess, and how you can check the validity of your solution (d) Describe the strategy you would use to solve the general BVP 4 pts using the shooting method. Describe the functions you need to write, what you need to guess, and...
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
Question 24 1 pts Using the shooting method for the following second-order differential equation governing the boundary value problem G.E: + EA (x) +u = L (x) € (0,L] B.C's: u () = 0 and EA (2) de Iz-L=F, the trapezoidal method is used to converts the problem into coupled integral equations solved at the quadrature points. None of the above. finite differences are used to convert the governing equation and boundary conditions of the problem into an analog set...
2. Use the method of separation of variables to solve the boundary value problem ( au = karu 0<x<L t > 0 (0,t) = 0, > 0 (1.1) -0. > 0 (u(a,0) - (x) 0<x<L. Be sure to detail exactly how f(x) enters your solution E-
Solve the following Boundary Value Problem using the given conditions Partial Differential Eq ST_0*T Ətər? Boundary Conditions Initial Conditions 180r + 10 T(1,0) = f(x) =( -180.c + 190 0 <r<.5 5<r <1)
Apply method of images and Fourier transformation to solve the following boundary value problem for the heat equation in the quarter plane, ut = 8uzz, cos 2 u(r,0 Uz (0, t) = 0, (10) lim u(x, t)=0 Apply method of images and Fourier transformation to solve the following boundary value problem for the heat equation in the quarter plane, ut = 8uzz, cos 2 u(r,0 Uz (0, t) = 0, (10) lim u(x, t)=0