solving an ODE with a constraint equation

Hi all,
I wondered if there is a numerical solver in MATLAB that can be used to solve this ODE with a constraint:
dy/dx = a/x;
y(0) = 0;
y dx = 1.
"y" is a function of "x", and "a" is an unknow constant that also needs to be solved.
It seems that this is a combination of ODE and an nonlinear equation, and is there any way that I can solve both simutaneously? Thank you.

1 件のコメント

Tong Bo
Tong Bo 2022 年 4 月 1 日
The example here is only a simple case and I can easily get a analytical solution. But is there a numerical solver that can solve this class of problems?

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

 採用された回答

Torsten
Torsten 2022 年 4 月 1 日

0 投票

As you said: You will have to couple a nonlinear solver with an ODE integrator.
I changed the ODE to dy/dx = a*x because of the singularity of your ODE at x=0.
a0 = 1;
a = fzero(@fun,a0)
% Check
res = fun(a)
function res = fun(a)
xstart = 0.0;
xend = 1.0;
fun = @(x,y) [a*x;y(1)];
xspan = [xstart,xend];
y0 = [0;0];
[t,y] = ode45(fun,xspan,y0);
res = y(end,2) - 1.0;
end

1 件のコメント

Tong Bo
Tong Bo 2022 年 4 月 1 日
Thank you for helping with this. Problem solved!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 4 月 1 日

0 投票

Typically this would be solved as a Boundary Value Problem, such as bvp4c() or bvp5c()

1 件のコメント

Tong Bo
Tong Bo 2022 年 4 月 1 日
Thank you for this reply.

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

カテゴリ

タグ

質問済み:

2022 年 4 月 1 日

コメント済み:

2022 年 4 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by