Problems with fmin. Trying to minimize a function with two unknowns and a vector that changes

7 visualizzazioni (ultimi 30 giorni)
Hi, I'm still a bit new to Matlab, but I have a problem that i can't seem to figure out. I know that fminsearch or fminunc usually minimize functions(constant ones at least) such as x^2+y. I have the following equation:
-log((1/beta)*(1+xi*(l(i,1)-u)/beta)^(-1/(xi-1)))
What I am looking to minimize is the the sum of all the logs from i = 1 to N, where l(i,1) for all N is a known number, and beta and xi are unknowns. I can do minimization for each function, but I don't know to minimize for the sum.
I've looked around and I haven't found any solutions yet.

Risposta accettata

Walter Roberson
Walter Roberson il 25 Gen 2016
obj_fun = @(beta, xi, L, U) sum( -log((1/beta)*(1+xi*(L-U)/beta)^(-1/(xi-1))) );
l = ...
u = ...
guess = randn(1,2);
fminsearch( @(bx) obj_fun(bx(1), bx(2), l, u), guess )
If you have constraints you would use fmincon instead of fminsearch.
Also if there are local minima then you might need to use a global solver instead of a local solver.
  2 Commenti
Ribal Abi Raad
Ribal Abi Raad il 25 Gen 2016
Hi, I tried your solution using the following piece of code:
obj_fun = @(beta,xi,l,u_n) sum(-log((1/beta)*(1+xi*(l-u_n)/beta)^(-1/xi-1))); l = loss_nu(i,1); u_n = 160; [phat] = fminsearch(@(bx) obj_fun(bx(1),bx(2),l,u_n),phat_guess) It worked fine, but the result I get is close to my phat_guess, and the result I should get is far off. I've tried with other variables for the phat_guess, and it always gives me the same numbers more or less.
Walter Roberson
Walter Roberson il 25 Gen 2016
I do not know what the value of i is there. You should be passing in an entire vector for your third parameter. And it is a good idea to not name a variable l (lower case L) as it is often difficult to tell the difference between that and the number 1.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by