Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fminsearch problem

Subject: fminsearch problem

From: dal.luc

Date: 26 Apr, 2011 09:37:46

Message: 1 of 6

Hello everybody,

I'am trying to use fminsearch but I got an error : I've surely did an
error but I don'ty see where.
Who can help me ?
Let
1. Y a vector of observations (Y_1, Y_2, ... Y_n)
2. X = (X_1,X_2, ... X_n)
3. the function y=myfun(x,a,b) and myfun(x,a,b) = 1+1/(1+a*exp(b*x))
I want to estimate a and b using the X and Y, minimizing the chi2 =
sum(Y_i - myfun(X_i,a,b)^2).
Let a0 and b0 the first estimations.
The line : [x,fval] = fminsearch(@myfun,[a0,b0],Y,X) send me an
error ...

If someone could help me, it would be great !
Thnaks

Subject: fminsearch problem

From: John D'Errico

Date: 26 Apr, 2011 10:03:04

Message: 2 of 6

"dal.luc" <dal.luc@gmail.com> wrote in message <706dbbf2-831e-4f31-8a65-dc13711e6e50@j25g2000vbr.googlegroups.com>...
> Hello everybody,
>
> I'am trying to use fminsearch but I got an error : I've surely did an
> error but I don'ty see where.
> Who can help me ?
> Let
> 1. Y a vector of observations (Y_1, Y_2, ... Y_n)
> 2. X = (X_1,X_2, ... X_n)
> 3. the function y=myfun(x,a,b) and myfun(x,a,b) = 1+1/(1+a*exp(b*x))
> I want to estimate a and b using the X and Y, minimizing the chi2 =
> sum(Y_i - myfun(X_i,a,b)^2).
> Let a0 and b0 the first estimations.
> The line : [x,fval] = fminsearch(@myfun,[a0,b0],Y,X) send me an
> error ...
>
> If someone could help me, it would be great !
> Thnaks

Surely, had you told us what error you got, we
might be better prepared to help you. Instead this
is now a guessing game, where we try to guess what
you did wrong.

Did you not define myfun properly as a function,
perhaps trying to define an m-file at the command
line, or worse?

Did you try to use / in myfun instead of ./ ?

Are you not passing in a,b properly to myfun?

Did you overload fminsearch by naming a file
with the same name?

Did you find some other silly error that I have not
imagined?

Tell us the complete error. MATLAB generates errors
to help you, so that the process of debugging things
is NOT a guessing game. Read the error.

John

Subject: fminsearch problem

From: dal.luc

Date: 26 Apr, 2011 12:14:52

Message: 3 of 6

On 26 avr, 12:03, "John D'Errico" <woodch...@rochester.rr.com> wrote:
> "dal.luc" <dal....@gmail.com> wrote in message <706dbbf2-831e-4f31-8a65-dc13711e6...@j25g2000vbr.googlegroups.com>...
> > Hello everybody,
>
> > I'am trying to use fminsearch but I got an error : I've surely did an
> > error but I don'ty see where.
> > Who can help me ?
> > Let
> > 1. Y a vector of observations (Y_1, Y_2, ... Y_n)
> > 2. X = (X_1,X_2, ... X_n)
> > 3. the function y=myfun(x,a,b) and myfun(x,a,b) = 1+1/(1+a*exp(b*x))
> > I want to estimate a and b using the X and Y, minimizing the chi2 =
> > sum(Y_i - myfun(X_i,a,b)^2).
> > Let a0 and b0 the first estimations.
> > The line : [x,fval] = fminsearch(@myfun,[a0,b0],Y,X) send me an
> > error ...
>
> > If someone could help me, it would be great !
> > Thnaks
>
> Surely, had you told us what error you got, we
> might be better prepared to help you. Instead this
> is now a guessing game, where we try to guess what
> you did wrong.
>
> Did you not define myfun properly as a function,
> perhaps trying to define an m-file at the command
> line, or worse?
>
> Did you try to use / in myfun instead of ./ ?
>
> Are you not passing in a,b properly to myfun?
>
> Did you overload fminsearch by naming a file
> with the same name?
>
> Did you find some other silly error that I have not
> imagined?
>
> Tell us the complete error. MATLAB generates errors
> to help you, so that the process of debugging things
> is NOT a guessing game. Read the error.
>

That's what I did of course ! I am not stupid
Thanks for your non help

Subject: fminsearch problem

From: Steven_Lord

Date: 26 Apr, 2011 13:40:52

Message: 4 of 6



"dal.luc" <dal.luc@gmail.com> wrote in message
news:a692e135-4465-4d39-8da8-4bab9ca58909@v11g2000prb.googlegroups.com...
> On 26 avr, 12:03, "John D'Errico" <woodch...@rochester.rr.com> wrote:
>> "dal.luc" <dal....@gmail.com> wrote in message
>> <706dbbf2-831e-4f31-8a65-dc13711e6...@j25g2000vbr.googlegroups.com>...

*snip*

>> Tell us the complete error. MATLAB generates errors
>> to help you, so that the process of debugging things
>> is NOT a guessing game. Read the error.
>>
>
> That's what I did of course ! I am not stupid
> Thanks for your non help

No, that is NOT what you did. Please post the full, complete text of the
error message. It should start with the word "Error" and probably stop at
the next appearance of the command prompt. For example, if you executed a
call to FZERO (I know you called FMINSEARCH; I'm just calling FZERO for
demonstration purposes) in release R2011a but specified a function that
didn't exist, you'd get this error:


>> fzero(@(x) nonexistentFunction, 1)
??? Error using ==> fzero at 301
FZERO cannot continue because user supplied function_handle ==>
@(x)nonexistentFunction
failed with the error below.

Undefined function or variable 'nonexistentFunction'.

>>


Your code should have displayed something like the text in the section
between the >> marks when the error occurred. That text is what John asked
you to post. That information was not in your original message.

Without that information, all anyone could do would be to guess wildly at
the cause of the problem, and that's not an efficient use of your time or
theirs.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: fminsearch problem

From: dpb

Date: 26 Apr, 2011 13:52:14

Message: 5 of 6

On 4/26/2011 7:14 AM, dal.luc wrote:
> On 26 avr, 12:03, "John D'Errico"<woodch...@rochester.rr.com> wrote:
...

>> Surely, had you told us what error you got, we
>> might be better prepared to help you. Instead this
>> is now a guessing game, where we try to guess what
>> you did wrong.
...

> That's what I did of course ! I am not stupid
> Thanks for your non help
...

Well, thanks for _your_ non-help, too...and rude besides... :(

Besides Steve's other hints, posting enough of the code including the
call and the function _verbatim_ copied and pasted, not retyped or
transliterated that can see the function definition and the call...

I'm suspicious when you write Y=(Y_1, Y_2, ...), etc., and the function
y=f(x) just as one possibility...responses are only as good as the
questions and questions are only as good as the precision and
completeness with which they are asked.

--

Subject: fminsearch problem

From: John D'Errico

Date: 26 Apr, 2011 14:14:05

Message: 6 of 6

"dal.luc" <dal.luc@gmail.com> wrote in message <a692e135-4465-4d39-8da8-4bab9ca58909@v11g2000prb.googlegroups.com>...
> On 26 avr, 12:03, "John D'Errico" <woodch...@rochester.rr.com> wrote:
> > "dal.luc" <dal....@gmail.com> wrote in message <706dbbf2-831e-4f31-8a65-dc13711e6...@j25g2000vbr.googlegroups.com>...
> > > Hello everybody,
> >
> > > I'am trying to use fminsearch but I got an error : I've surely did an
> > > error but I don'ty see where.
> > > Who can help me ?
> > > Let
> > > 1. Y a vector of observations (Y_1, Y_2, ... Y_n)
> > > 2. X = (X_1,X_2, ... X_n)
> > > 3. the function y=myfun(x,a,b) and myfun(x,a,b) = 1+1/(1+a*exp(b*x))
> > > I want to estimate a and b using the X and Y, minimizing the chi2 =
> > > sum(Y_i - myfun(X_i,a,b)^2).
> > > Let a0 and b0 the first estimations.
> > > The line : [x,fval] = fminsearch(@myfun,[a0,b0],Y,X) send me an
> > > error ...
> >
> > > If someone could help me, it would be great !
> > > Thnaks
> >
> > Surely, had you told us what error you got, we
> > might be better prepared to help you. Instead this
> > is now a guessing game, where we try to guess what
> > you did wrong.
> >
> > Did you not define myfun properly as a function,
> > perhaps trying to define an m-file at the command
> > line, or worse?
> >
> > Did you try to use / in myfun instead of ./ ?
> >
> > Are you not passing in a,b properly to myfun?
> >
> > Did you overload fminsearch by naming a file
> > with the same name?
> >
> > Did you find some other silly error that I have not
> > imagined?
> >
> > Tell us the complete error. MATLAB generates errors
> > to help you, so that the process of debugging things
> > is NOT a guessing game. Read the error.
> >
>
> That's what I did of course ! I am not stupid

Your lack of intelligent response belies that statement.

Tell us what you did if you expect a rational answer.
I suggested three completely different possibilities,
all of which were indeed possible based on your original
post.

If not, then perhaps the only rational answer you will
get is from matlab itself...

>> format rat
>> pi
ans =
     355/113

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us