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!