I am stuck in boundary condition which can't be slove with ode45.
to solve this problem can you please help me with boundary condition and convert it BVP4C ?
my progress is -
tRange = [0 10];
function dYdt = odefun(t,Y)
% Extract Y1,Y2,Y3 the element of Y
Y1 = Y(1);
Y2 = Y(2);
Y3 = Y(3);
% Expression for dY1dt, dY2dt,dY3dt.
dY1dt = Y2;
dY2dt = Y3;
dY3dt = -(1/2)*Y1*Y3;
% Create dYdt, column vector containing dY1dt, dY2dt, and dY3dt
dYdt = [dY1dt; dY2dt; dY3dt];
end

 採用された回答

Torsten
Torsten 2022 年 9 月 29 日

1 投票

tmesh = linspace(0,10,100);
solinit = bvpinit(tmesh, [0 1 0]);
sol = bvp4c(@odefun, @bcfcn, solinit);
plot(sol.x, sol.y)
function dYdt = odefun(t,Y)
% Extract Y1,Y2,Y3 the element of Y
Y1 = Y(1);
Y2 = Y(2);
Y3 = Y(3);
% Expression for dY1dt, dY2dt,dY3dt.
dY1dt = Y2;
dY2dt = Y3;
dY3dt = -(1/2)*Y1*Y3;
% Create dYdt, column vector containing dY1dt, dY2dt, and dY3dt
dYdt = [dY1dt; dY2dt; dY3dt];
end
function res = bcfcn(ya,yb)
res = [ya(1);ya(2);yb(2)-1];
end

4 件のコメント

Syed Arafun Nabi
Syed Arafun Nabi 2022 年 9 月 29 日
Thanks a lot. Here doesnot the 1st one will plot y vs t & 2nd one dy/dt vs t?
subplot(2,1,1), plot(sol.x, sol.y)
subplot(2,1,2), plot(sol.x, sol.y(2,:))
Torsten
Torsten 2022 年 9 月 29 日
Yes, and sol.y(3,:) is d^2y/dt^2.
Shriram
Shriram 2023 年 12 月 1 日
Thanks for your answer!
I was curious about how to implemenet this method for a problem where the boundary conditions are as follows:
y(0) = 0, y'(2) = 0 and y'(10) = 1?
How would we formulate this in MATLAB?
Torsten
Torsten 2023 年 12 月 2 日
編集済み: Torsten 2023 年 12 月 2 日
You need two conditions at t = 2, not only one. Then you can solve the problem first from t=0 to t=2 with a total of 3 boundary conditions (one at t=0, two at t=2) and continue solving from t=2 to t=10, again with a total of three conditions given (two at t=2, one at t=10).
Note that the solution might have some discontinuous derivatives in t=2.
If you only prescribe a total of three conditions, there is no unique solution to the problem. BVP4C cannot be used in this case. Sometimes it's possible to get a parameter-dependent solution with "dsolve".

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2022 年 9 月 29 日

編集済み:

2023 年 12 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by