How to formulate the initial state vector for a BVP

2 visualizzazioni (ultimi 30 giorni)
If I have the following BVP, I am trying to solve, via shooting method. How would I formulate the state initial conditions given Dirichlet boundary conditions? I would use RK4 (given below) to solve two initial guesses of my second inital condition, and then I would interpolate to find x2(0). I guess the only trouble I am having is turning u(1)=1 into the inital state vector. Is it just uo[1:5], with 5 being an initial guess to x2(0).?
function u = RK4(f,x,u0)
%
% RK4System uses RK4 method to solve a system of first-order
% initial-value problems in the form u' = f(x,u), u(x0) = u0.
%
% u = RK4(f,x,u0), where
%
% f is an anonymous m-dim. vector function representing f(x,u),
% x is an (n+1)-dim. vector representing the mesh points,
% u0 is an m-dim. vector representing the initial state vector,
%
% u is an m-by-(n+1) matrix, each column the vector of solution
% estimates at a mesh point.
%
u(:,1) = u0; % The first column is set to be the initial vector u0
h = x(2) - x(1); n = length(x);
for i = 1:n-1,
k1 = f(x(i),u(:,i));
k2 = f(x(i)+h/2,u(:,i)+h*k1/2);
k3 = f(x(i)+h/2,u(:,i)+h*k2/2);
k4 = f(x(i)+h,u(:,i)+h*k3);
u(:,i+1) = u(:,i)+h*(k1+2*k2+2*k3+k4)/6;
end

Risposte (0)

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by