Optimization to find a deterministic number

2 views (last 30 days)
Wajih IMLIKI on 30 Apr 2022
Edited: John D'Errico on 30 Apr 2022
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

Answers (1)

John D'Errico
John D'Errico on 30 Apr 2022
Edited: John D'Errico on 30 Apr 2022
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)
g = 
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
f(x) = 
This results in
Esol = matlabFunction(solve(f == g,E))
Esol = function_handle with value:
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.
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)
xmin = -0.6508
Emin = -0.9145
[xmax,Emax] = fminbnd(@(x) -Esol(x),-1,1);
Emax = -Emax
Emax = 0.9145
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.


Community Treasure Hunt

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

Start Hunting!