-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathbvp2ordshoot.m
36 lines (36 loc) · 1011 Bytes
/
bvp2ordshoot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
% Program for solving 2PBVP for a second-order system
% y''=f(t,y,y'),
% with end conditions on dependent variable,
% y(t0)=a; y(tf)=b,
% by a simple shooting method.
% Requires 'ode2ord.m' for specifying the differential equation
% for integration by MATLAB's RK-4(5) IVP code 'ode45.m'.
% (c) 2009 Ashish Tewari
% Solution vector: Y=[y, dy/dt]'; Time vector: T.
function [T,Y]=bvp2ordshoot(t0,tf,a,b)
c=-4; % Constant for shooting algorithm
tol=1e-6; % Terminal error tolerance
yp=(b-a)/(tf-t0) % Initial guess of dy/dt(0)
% Initial value problem solution by 'ode45.m'
[T,Y]=ode45('ode2ord',[t0 tf],[a yp]');
n=size(T,1);
y1=Y(n,1)
y1dot=Y(n,2)
res=abs(y1-b)
i=1;
% Iteration for terminal error follows:
while res>tol
i=i+1
yp=c*(y1-b)+yp
T=[];Y=[];
[T,Y]=ode45('ode2ord',[t0 tf],[a yp]');
n=size(T,1);
y1=Y(n,1)
y1dot=Y(n,2)
res=abs(y1-b)
end
% Program for specifying the differential equation
% for integration by MATLAB's RK-4(5) IVP code 'ode45.m'.
function dydx=ode2ord(x,y)
dydx=[y(2)
-4*y(1)^2];