Optimization to find a deterministic number
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
John D'Errico
le 30 Avr 2022
Modifié(e) : John D'Errico
le 30 Avr 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)
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 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!