Find minimum in one variable only
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a complicated two-variable function f(x,t), for 0 < x, t < 1.
My goal is to estimate the integral from 0 to 1 of min_{0<t<1} |f(x,t)|.
I have tried using fminbnd, but I'm having problems since the input is a function of two variables.
My initial definition of f looked like
syms x t
f = cos(x)*exp(t^2); % actual function is much more complicated than this.
Note that I do not expect to be able to locate extrema analytically.
The best I can do so far is compute the minimum at a number of x-values, like this:
d = []; % vector to hold minima
N = 100; % number of x-values to check
for j = 0 : N
f = @(t)cos(j/N)*exp(t^2);
d = [d, [fminbnd(f,0,1)]];
end;
I can then use the vector d to approximate the integral I want. However, this seems slow and inefficient. Any suggestions would be welcome.
0 commentaires
Réponses (1)
Rik
le 8 Août 2018
You can use a trick to make it a single input function: use a vector.
f = @(x,t)cos(x)*exp(t^2);
B=fminbnd(@(b)f(b(1),b(2)),[0;1],[0;1]);
I use this trick often with fminsearch if I want to fit a function, but don't know if the end user has the curve fitting toolbox:
%needed input: x and yx
% Objective function (Exponential)
y = @(b,x) b(1)*exp(b(2)*x);
% Ordinary Least Squares cost function
OLS = @(b) sum((y(b,x) - yx).^2);
opts = optimset('MaxFunEvals',50000, 'MaxIter',10000);
% Use 'fminsearch' to minimise the 'OLS' function
fit_output = fminsearch(OLS, intial_b_vals, opts);
0 commentaires
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!