How to solve boundary value problem using shooting method (ode45)?

5 次查看(过去 30 天)
Hi,
I am trying to solve a differential equation using shooting method. I have a differential equation of the form:
dydx = 6/h^3*(1/e/r*(V-U)-V*h);
r and h are defined in the form of vectors in the main function. The value of 'e' can vary from 0.1 to 0.001 and is constant for a given run. The BCs are y(-1) = 1 and y(1) = 0. U and V are the parameters which I am trying to determine. I am using ode45 to integrate the differential equation from the left boundary y(-1) = 1 and then using fsolve to set the value at the right boundary to 0. This is my code:
global x_range H R Pf0 Pb0 e
xf = 1;
xb = -1;
Pf0 = 0;
Pb0 = 1;
U0 = 1;
V0 = 1;
xf0 = [U0;V0];
e = 0.01; %can vary from 0.1 to 0.001
x_range = linspace(xb,xf,100);
H = ones(1,100);
R = 1-e*H;
fun = @(x) ode_solver(x);
[xf_opt,fval,exitflag] = fsolve(fun,xf0);
function y = ode_solver(x0)
global x_range U V Pb0
U = x0(1);
V = x0(2);
[xf,yf] = ode45(@diff_eqn,x_range,Pb0);
y = yf(1,end)
figure(1), plot(xf,yf)
function dydx = diff_eqn(x,~)
global x_range R H U V e
r = spline(x_range,R,x);
h = spline(x_range,H,x);
dydx = 6/h^3*(1/e/r*(V-U)-V*h);
The code returns that no solution was found. The value of y at the right boundary goes below 0. Am I doing something wrong here? Can I approach the problem differently?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by