how to put a vector in function
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hello all;
I want to write a function like below, and minimum it with "fminsearch" but I cant!
function F_m_p_cmp=fmp_cmp(cc)
mm=3
for ii=1:mm
for t=1:24
ex(ii,t)=cc(t)*(Uu(1,t,ii)+Uu(2,t,ii)+Uu(3,t,ii))+sum(Cc(:,t,ii))
end
end
expp=p*ex;
eexp=exp(expp);
F_m_p_cp=(1/p)*log10(sum(ex));
end
" cc" should be a 1 by 24 vector. could you please help me?
1 comentario
John D'Errico
el 15 de Ag. de 2014
Note that you will never be happy with trying to solve a 24 variable problem with fminsearch. It simply is NOT designed for that many unknowns. Use a better optimizer, such as fmincon or fminunc.
Respuestas (1)
Star Strider
el 15 de Ag. de 2014
You have to define ‘cc’ as a (1x24) vector as your initial parameter estimate vector ( x0 in the documentation ) to fminsearch.
You also have to pass Uu, Cc and p to your ‘fmp_cpm’ function. If Uu, Cc and p are already in your workspace, I would create an anonymous objective function to do that.
First, rewrite your function statement as:
function F_m_p_cmp=fmp_cmp(cc, Uu, Cc, p)
then create your objective function as:
objfcn = @(cc) fmp_cmp(cc, Uu, Cc, p);
so your call to fminsearch becomes:
cc0 = rand(1,24); % Choose whatever (1x24) vector for ‘cc’ you want
cc_est = fminsearch(objfcn, cc0);
No promises because I can’t run your code, but this should get you started.
6 comentarios
Star Strider
el 15 de Ag. de 2014
My pleasure!
You cannot set constraints with fminsearch. You can normalise them inside your fmp_cmp function with:
cc = cc/sum(cc);
as the first statement in the function, but this is not actually constraining them. I can’t help you with delta. I have no idea what you are doing.
If you want to optimise with constraints, you will have to use one of the Optimization Toolbox solvers such as fmincon.
Ver también
Categorías
Más información sobre Nonlinear Least Squares (Curve Fitting) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!