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: fminsearch
Replies: 7   Last Post: Apr 17, 2009 12:11 PM

Advanced Search

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

Posts: 10
Registered: 4/15/09
Re: fminsearch
Posted: Apr 16, 2009 6:18 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gs8a0h$cjl$1@fred.mathworks.com>...
> "Andrea Asoni" <andrea.asoni@lycos.com> wrote in message <gs87b1$gkf$1@fred.mathworks.com>...
> > hi,
> >
> > i have some problems with fminsearch. i am trying to make it work on a simple example (similar in structure to my far more complicated problem) but still can't.
> >
> > I have the following function:
> >
> > %maxlik.m
> > function L=maxlik(z,b)
> > global x y N ev z b;
> >
> > for i=1:N;
> > if ev(i,1)==1;
> > p(i,1)=z*x(i,1)+b*y(i,1);
> > else
> > p(i,1)=z*x(i,1)+b^2*y(i,1);
> > end
> > end
> > L=-sum(p)
> > end
> >
> > and i have the following main program:
> > id=m(:,1); ev=m(:,2); x=m(:,3); y=m(:,4); c=m(:,5); te=m(:,6);
> > N=length(c);
> >
> > %initial conditions
> > z0=1;
> > b0=1;
> > global x y N ev z b;
> >
> > [z,b]=fminsearch(@maxlik,[z0,b0]);
> >
> > but when i run it i get the following error message...
> >
> > ??? Subscripted assignment dimension mismatch.
> >
> > Error in ==> maxlik at 6
> > p(i,1)=z*x(i,1)+b*y(i,1);
> >
> > Error in ==> fminsearch at 175
> > fv(:,1) = funfcn(x,varargin{:});
> >
> > Error in ==> prova at 29
> > [z,b]=fminsearch(@maxlik,[z0,b0]);
> >
> > what does it mean? what's the error?

>
> Why do you use global variables here? You are passing
> in z and b. Making them global is just silly, and a great
> way to introduce bugs into your code.
>
> On your actual problem we cannot know what you have
> done, but I'd guess that z or b are vectors or arrays.
>
> How will they fit into a scalar result?
>
> John


maybe i got the code all wrong (it is my third day of self-thought matlab!) but z and b are scalars.
p(i,1) is defined as the (i,1)th element of vector x times z plus the (i,1)th element of vector y times b.

i want to maximize (with respect to z and b) the function L which is the sum of all the p's (who should be functions of z,b and the 'data' x,y)...
does it make any sense? did i get it all wrong?



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.