Got Questions? Get Answers.
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 mle parameters

Subject: fminsearch mle parameters

From: nora12345

Date: 23 Mar, 2008 22:03:27

Message: 1 of 5

hello,

I am trying to use fminsearch to solve for the paramter phee. Whenever
I type:
phiHat = fminsearch(exact(z,x),z,x);

I get the error message:

??? Error using ==> fcnchk at 105
FUN must be a function, a valid string expression,
or an inline function object.

Error in ==> fminsearch at 178
funfcn = fcnchk(funfcn,length(varargin));

my function is defined as:
function result = exact( h,q)


% Estimation
% =============
x = q(:); % should be column vectors !
z =h(:);
phee = (inv(x'*x))*(x'*z);
N = length(x);
sig2 = (z-phee*x)'*(z-phee*x)/N;
w = (N/2/log(2*pi))+(N/2)*log(sig2)+((z-phee*x)'*(z-phee*x))/
2*sig2;
result = struct( 'phee',phee);
end

I have no idea what I am doing wrong, any help would be welcome!

-Nora

Subject: fminsearch mle parameters

From: Miroslav Balda

Date: 23 Mar, 2008 22:23:01

Message: 2 of 5

nora12345 <jcoetsee@gmail.com> wrote in message
<adcfc16a-99b3-48c4-95a9-c22330e70f00@8g2000hsu.googlegroups.com>...
> hello,
>
> I am trying to use fminsearch to solve for the paramter
phee. Whenever
> I type:
> phiHat = fminsearch(exact(z,x),z,x);
>
> I get the error message:
>
> ??? Error using ==> fcnchk at 105
> FUN must be a function, a valid string expression,
> or an inline function object.
>
> Error in ==> fminsearch at 178
> funfcn = fcnchk(funfcn,length(varargin));
>
> my function is defined as:
> function result = exact( h,q)
>
>
> % Estimation
> % =============
> x = q(:); % should be column vectors !
> z =h(:);
> phee = (inv(x'*x))*(x'*z);
> N = length(x);
> sig2 = (z-phee*x)'*(z-phee*x)/N;
> w =
(N/2/log(2*pi))+(N/2)*log(sig2)+((z-phee*x)'*(z-phee*x))/
> 2*sig2;
> result = struct( 'phee',phee);
> end
>
> I have no idea what I am doing wrong, any help would be
welcome!
>
> -Nora

Hi Nora
As first read help to the function fminsearch. You will read
there, that the first argument to fminsearch is a handle (or
name = string) of the function to be minimized.
The second argument is your estimate of the solution. It is
a strting point of iterations. Then, optional parameters
controlling iteration process may be set, otherwise default
parameters are used.

Therefore, you have to call

phiHat = fminsearch('exact',[z;x]);

where z and x are initial estimates of a solution, and build

function f = exact(p),
% your code for the function exact,

where p is a vector of two unknowns, p=[z;x].

Hope it helps.

Mira

Subject: fminsearch mle parameters

From: nora12345

Date: 23 Mar, 2008 22:55:43

Message: 3 of 5

On Mar 23, 6:23=A0pm, "Miroslav Balda" <miroslav.nos...@balda.cz> wrote:
> nora12345 <jcoet...@gmail.com> wrote in message
>
> <adcfc16a-99b3-48c4-95a9-c22330e70...@8g2000hsu.googlegroups.com>...
>
>
>
> > hello,
>
> > I am trying to use fminsearch to solve for the paramter
> phee. Whenever
> > I type:
> > phiHat =3D fminsearch(exact(z,x),z,x);
>
> > I get the error message:
>
> > ??? Error using =3D=3D> fcnchk at 105
> > FUN must be a function, a valid string expression,
> > or an inline function object.
>
> > Error in =3D=3D> fminsearch at 178
> > funfcn =3D fcnchk(funfcn,length(varargin));
>
> > my function is defined as:
> > function result =3D exact( h,q)
>
> > % Estimation
> > % =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> > x =A0 =A0 =A0 =3D q(:); % should be column vectors !
> > z =A0 =A0 =A0 =3Dh(:);
> > phee =A0 =A0 =3D (inv(x'*x))*(x'*z);
> > N =A0 =A0 =A0 =3D length(x);
> > sig2 =A0 =A0=3D (z-phee*x)'*(z-phee*x)/N;
> > w =A0 =A0 =A0=3D
>
> (N/2/log(2*pi))+(N/2)*log(sig2)+((z-phee*x)'*(z-phee*x))/
>
> > 2*sig2;
> > result =3D struct( 'phee',phee);
> > end
>
> > I have no idea what I am doing wrong, any help would be
> welcome!
>
> > -Nora
>
> Hi Nora
> As first read help to the function fminsearch. You will read
> there, that the first argument to fminsearch is a handle (or
> name =3D string) of the function to be minimized.
> The second argument is your estimate of the solution. It is
> a strting point of iterations. Then, optional parameters
> controlling iteration process may be set, otherwise default
> parameters are used.
>
> Therefore, you have to call
>
> phiHat =3D fminsearch('exact',[z;x]);
>
> where z and x are initial estimates of a solution, and build
>
> function f =3D exact(p),
> % =A0 your code for the function exact,
>
> where p is a vector of two unknowns, p=3D[z;x].
>
> Hope it helps.
>
> Mira- Hide quoted text -
>
> - Show quoted text -

Thanks Mira! I will try that...z and x were my input vectors and I
was trying to solve for phee...does this make a difference?
-Nora

Subject: fminsearch mle parameters

From: Miroslav Balda

Date: 24 Mar, 2008 00:03:02

Message: 4 of 5

nora12345 <jcoetsee@gmail.com> wrote in message
<539baf83-2c03-4be9-8b53-6d6f4eb863c6@d62g2000hsf.googlegroups.com>...
:
SNIP
:
> Thanks Mira! I will try that...z and x were my input
vectors and I
> was trying to solve for phee...does this make a difference?
> -Nora

Hi Nora,
I didn't study your description of the function to be
minimized.
Basically, you have to state what are your unknowns v =
variables which the function fminsearch will vary to get the
minimum of your function. It seems me from your description
that your call of the function fminsearch should be a script

x0 = q(:);
z0 = h(:);
N = length(x0);
global N

v = fminsearch('exact',[x0;z0]);
phee = result(v)
sig2 = (z-phee*x)'*(z-phee*x)/N;
w = (N/2/log(2*pi))+(N/2)*log(sig2)+...
((z-phee*x)'*(z-phee*x))/2*sig2;

and the function exact:

function result = exact(v)
global N
x = v(1:N);
z = v(N+1:end);
result = x'*z/(x'*x); % this is phee

I hope I have not made any error. I should like to stress
out that it holds for all elements of v being unknowns.
Good night!

Mira

Subject: fminsearch mle parameters

From: nora12345

Date: 24 Mar, 2008 00:16:15

Message: 5 of 5

On Mar 23, 8:03=A0pm, "Miroslav Balda" <miroslav.nos...@balda.cz> wrote:
> nora12345 <jcoet...@gmail.com> wrote in message
>
> <539baf83-2c03-4be9-8b53-6d6f4eb86...@d62g2000hsf.googlegroups.com>...
> :
> SNIP
> :
>
> > Thanks Mira! =A0I will try that...z and x were my input
> vectors and I
> > was trying to solve for phee...does this make a difference?
> > -Nora
>
> Hi Nora,
> I didn't study your description of the function to be
> minimized.
> Basically, you have to state what are your unknowns v =3D
> variables which the function fminsearch will vary to get the
> minimum of your function. It seems me from your description
> that your call of the function fminsearch should be a script
>
> x0 =3D q(:);
> z0 =3D h(:);
> N =3D length(x0);
> global N
>
> v =3D fminsearch('exact',[x0;z0]);
> phee =3D result(v)
> sig2 =3D (z-phee*x)'*(z-phee*x)/N;
> w =3D (N/2/log(2*pi))+(N/2)*log(sig2)+...
> ((z-phee*x)'*(z-phee*x))/2*sig2;
>
> and the function exact:
>
> function result =3D exact(v)
> global N
> x =3D v(1:N);
> z =3D v(N+1:end);
> result =3D x'*z/(x'*x); % this is phee
>
> I hope I have not made any error. I should like to stress
> out that it holds for all elements of v being unknowns.
> Good night!
>
> Mira

Thank-you!!!!! :)

Tags for 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