Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: fminsearch
Replies: 7   Last Post: Apr 17, 2009 12:11 PM

 Messages: [ Previous | Next ]
 Andrea Asoni Posts: 10 Registered: 4/15/09
Re: fminsearch
Posted: Apr 16, 2009 6:18 PM

"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?

Date Subject Author
4/16/09 Andrea Asoni
4/16/09 jrenfree@gmail.com
4/16/09 John D'Errico
4/16/09 John D'Errico
4/16/09 Andrea Asoni
4/16/09 John D'Errico
4/17/09 Andrea Asoni
4/16/09 jrenfree@gmail.com