How to solve a system of second order nonlinear differential equations with boundary conditions

33 ビュー (過去 30 日間)
Hello, I am having troubles solving a system of second order nonlinear equations with boundary conditions using MATALB Here is the equations:
f''(t)=3*f(t)*g(t) ; g''(t)=4f(t)*g(t);
the boundary conditions are: f(0)=1.5 et g'(o)=0; g(2)=3 et f'(2)=f(2)
  14 件のコメント
Alex Sha
Alex Sha 2021 年 6 月 18 日
Refer to the result below please:
g(0) = -1.44989398376437
f'(0) = -2.78301182421201



J. Alex Lee
J. Alex Lee 2021 年 6 月 12 日
This is a boundary value problem, so probably the most straightforward way is to use bvp4c or bvp5c if you want to solve numerically, and if so don't bother with syms at all. It looks like you already figured how to break your 2nd order equations into first order ones so in addition to f and g you must have j = f' and k = g' or something. So your original question about the BCs you can pose as
0=k(0) and j(2)=f(2)
  4 件のコメント
J. Alex Lee
J. Alex Lee 2021 年 6 月 14 日
believe me, i had some trouble understanding the syntax for bvp4c/5c as well!
It is not at all intuitive to me either what the initial guess should be. bvp4c failed with the trivial initial guess (zeros), so i just picked something random.
I did at least check the BCs are satisfied, but no I didn't really check the ODE...I figured that can be tested by running your IVP integration.


その他の回答 (2 件)

Paul 2021 年 6 月 13 日
I was not able to solve the problem for the boundary conditions specified at t=2. But I was able to get a resonable looking solution for the same problem with boundry conditions specified at t = 0.5 by posing it as an optimization problem to solve for the unknown initial conditions that result in the boundary conditions being satisfied.
I'm assuming the equations to be solved are:
f''(t) = 3*f(t)*g(t) + 5
g''(t) = 4*g(t)*f(t) + 7
with initial conditions:
f(0) = 1.5, g'(0) = 0
and boundary constraints defined at tf = 0.5:
g(tf) = 3, f(tf) = f'(tf)
Here is the code:
odeFun = @(t,y) ([y(2); 3*y(1)*y(3) + 5; y(4); 4*y(1)*y(3) + 7]);
tspan = [0 .5];
% solve for the unknown initial conditions with an initial guess
x0 = fminsearch(@myfun,[0;0.01]);
% compute the solution
y0 = [1.5 x0(1) x0(2) 0];
[t,y] = ode45(odeFun,tspan,y0,odeset('MaxStep',0.001));
% verify the solution satisfies the boundary conditions
[1.5-y(1,1) 0-y(1,4) y(end,1)-y(end,2)]
ans = 1×3
1.0e+-4 * 0 0 -0.1298
% (approximately) verify the solution satisfies the differential equation
for ii = 1:4
ydot(:,ii) = gradient(y(:,ii),t);
yddot(:,ii) = gradient(ydot(:,ii),t);
plot(t,yddot(:,1) - (3*y(:,1).*y(:,3) + 5)),grid
plot(t,yddot(:,3) - (4*y(:,1).*y(:,3) + 7)),grid
function f = myfun(x)
% y1(t) = f(t)
% y2(t) = f'(t)
% y3(t) = g(t)
% y4(t) = g'(t)
% y1p(t) = f'(t) = y2(t);
% y2p(t) = f''(t) = 3*f(t)*g(t) + 5 = 3*y1(t)*y3(t) + 5
% y3p(t) = g'(t) = y4(t)
% y4p(t) = g''(t) = 4*g(t)*f(t) + 7 = 4*y1(t)*y3(t) + 7
% y0 = [f(0) f'(0) g(0) g'(0)] = [1.5 x(1) x(2) 0]
odeFun = @(t,y) ([y(2); 3*y(1)*y(3) + 5; y(4); 4*y(1)*y(3) + 7]);
tspan = [0 .5];
y0 = [1.5 x(1) x(2) 0];
[t,y] = ode45(odeFun,tspan,y0,odeset('MaxStep',0.001));
f = (y(end,3) - 3)^2 + (y(end,2) - y(end,1))^2;
My quick experiments showed the solution blows up pretty quickly for tf > 1, which is probably why ode45 had trouble. I didn't experiment with any of the ode45 parameters or with the initial guess for the initial conditions to see if a solution could be obtained for tf = 2. Maybe that's doable.
  12 件のコメント
Lewis Fer
Lewis Fer 2021 年 6 月 20 日
Thank's Alex Sha, but how can I obtain the graphlike you did the first time, and if you have a direct link to download this solver I will use it for the first time ?


Alex Sha
Alex Sha 2021 年 6 月 20 日
Hi, the chart will be given automatically in 1stOpt UI, also you can make chart yourself by using the result data given above. 1stOpt is a commercial software, there is no download linker as my know.
  1 件のコメント
Lewis Fer
Lewis Fer 2021 年 6 月 20 日
Thank's alex I use MATLAB and we have not this software.


Community Treasure Hunt

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

Start Hunting!

Translated by