The Math Forum

Search All of the Math Forum:

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

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

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

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 17, 2009 12:11 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"John D'Errico" <> wrote in message <gs8ed6$mig$>...
> "Andrea Asoni" <> wrote in message <gs8aqp$1u6$>...

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

> Sorry, but I don't buy it. ;-)
> MATLAB does not lie, so it must be you who
> are mistaken here.
> Read the error message.

> > > ??? Subscripted assignment dimension mismatch.
> > >
> > > Error in ==> maxlik at 6
> > > p(i,1)=z*x(i,1)+b*y(i,1);
> > >

> It refers to the line above. Since i is a scalar,
> defined by the for loop above it, we know that
> p(i,1) is a scalar.
> Likewise, x(i,1) and y(i,1) are scalars. If either
> of them were empty, then you should have
> gotten a different error message.
> You can only have an assignment mismatch if
> the result on the right hand side of this expression
> is not a scalar. There are two ways for that to
> happen. The right hand side must be either an
> empty array, or it must be a vector or an array.
> It will be empty if either of z or b is empty, or
> if they are vectors or matrices.
> You need to use the debugger to identify which
> is happening. Also, as I said in my first response,
> learn to do without the globals. This may well
> be one of the reasons you have this error in the
> first place. It is very easy to have a variable
> stepped on without your realizing it.
> John

Thanks to all. i changed the maxlik function to

function L=maxlik(z)
global x y N ev;

for i=1:N;
if ev(i,1)==1;

and z=fminsearch(@maxlik,init)

and it works. it seems that for fminsearch is better to define a vector with two components (the vector being the variable i am optimizing over) rather than two scalars and optimize over those.

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.