Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: myfun: Attempted to access p(3); index out of bounds because numel(p)=2
Replies: 1   Last Post: Nov 11, 2013 5:33 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jonas

Posts: 1
Registered: 11/11/13
myfun: Attempted to access p(3); index out of bounds because numel(p)=2
Posted: Nov 11, 2013 4:56 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hey,
although I tried to google it, I couldn't find the right examples how to make (p)=3!
Thank you for your help!

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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.