How can I solve this myfun/numel problem?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jonas
el 11 de Nov. de 2013
Respondida: Image Analyst
el 11 de Nov. de 2013
function F = myfun(p)
s1 =(exp(5-p(1)))/(1+exp(5-p(1))+exp(3.5-p(2))+exp(5-p(3)));
s2 =(exp(3.5-p(2)))/(1+exp(5-p(1))+exp(3.5-p(2))+exp(5-p(3)));
s3 =(exp(5-p(3)))/(1+exp(5-p(1))+exp(3.5-p(2))+exp(5-p(3)));
F = [s1+(p(1)-1)*(-s1)*(1-s1)+(p(2)-1)*(s1*s2);
s2+(p(1)-1)*(s1*s2)+(p(2)-1)*(-s2)*(1-s2);
s3+(p(3)-1)*(-s3)*(1-s3)];
p0 = [-5; -5];
options = optimoptions('fsolve','Display','iter');
[p,fval] = fsolve(@myfun,p0,options)
Attempted to access p(3); index out of bounds because numel(p)=2.
Error in myfun (line 2)
s1 =(exp(5-p(1)))/(1+exp(5-p(1))+exp(3.5-p(2))+exp(5-p(3)));
Error in fsolve (line 217)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot
continue.
0 comentarios
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 11 de Nov. de 2013
If p has 2 elements, you'll have to use ./ instead of /, like this:
s1 =(exp(5-p(1))) ./ (1+exp(5-p(1))+exp(3.5-p(2))+exp(5-p(3)));
Same for the other equations. For F, use .* (dot star) instead of * (star).
0 comentarios
Ver también
Categorías
Más información sobre Tables 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!