Optimization to find a deterministic number
1 回表示 (過去 30 日間)
古いコメントを表示
Hi
If we have a deterministic number eps such as a function f(x) = x^7 + eps equal another function g(x) the result of a ode y``+4y=0 [y(0)=0 / y`(0)=2], how can we use optimization in matlab to find the upper and lower limit of the eps range such as f(x)= g(x) between x=-1 and x=1??
Thanks in advance
0 件のコメント
回答 (1 件)
John D'Errico
2022 年 4 月 30 日
編集済み: John D'Errico
2022 年 4 月 30 日
Huh? This question is pretty confusing. But let me see where it goes.
First, it seems you claim that g(x) is the solution of an ODE. But the ODE has a known solution, so this part is trivial.
syms y(x)
dy = diff(y);
g = dsolve(diff(y,2) + 4*y == 0,y(0)==0,dy(0) == 2)
In fact, the solution is even simpler than I might have thought. Now, you have some function f(x). In this case you have f(x)=x^7+E. (DO NOT NAME YOUR VARIABLES eps. eps is a useful function. Do NOT overload the name of existing functions in MATLAB, else you will later be asking the plaintive question of why your code does not run.)
But you are now setting f(x) == g(x). So we have
syms E
f(x) = x^7 + E
This results in
Esol = matlabFunction(solve(f == g,E))
Effectively, E can be viewed as a function of x itself. Now you wish to know the range of the function Esol, over the domain [-1,1] for x.
fplot(Esol,[-1,1])
From the plot, we see there are two local minima, as well as two local maxima. The end points of the interval matter here.
[xmin,Emin] = fminbnd(Esol,-1,1)
[xmax,Emax] = fminbnd(@(x) -Esol(x),-1,1);
Emax = -Emax
If the ODE were more complicated, so no analytical solution exists, then you would need to work harder. There are many things you could do however. Still not too difficult.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!