Optimization to find a deterministic number

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

답변 (1개)

John D'Errico
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)
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:
@(x)sin(x.*2.0)-x.^7
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)
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.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

태그

질문:

2022년 4월 30일

편집:

2022년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by