### Tags: define, etta, fminsearch, function, gammai, lambda, matlab, multiple, multipleparameters, parameter, programming, regarding, runnign, themselves, theta, vectors

# multiple parameter fminsearch

On Programmer » Matlab

4,533 words with 3 Comments; publish: Wed, 07 May 2008 17:59:00 GMT; (20078.13, « »)

I have a question regarding runnign fminsearch with multiple

parameters that are vectors themselves: theta etta lambda and gamma

I define a function m2 as:

function [min]=m2(theta, etta, lambda, gamma)

but then when I call it:

[theta, etta, lambda,

gamma]=fminsearch(.matlab.todaysummary.com.m2,[theta0;etta0;lamb

da0;gamma0],opts);

it gives me an error message saying that "Input argument 'theta' is

undefined."

am I misspecifying the fminsearch?

thanks,

olga

*http://matlab.todaysummary.com/q_matlab_40678.html*

All Comments

Leave a comment...

- 3 Comments
- olga gorbachev wrote:
>

> I have a question regarding runnign fminsearch with multiple

> parameters that are vectors themselves: theta etta lambda and gamma

> I define a function m2 as:

> function [min]=m2(theta, etta, lambda, gamma)

> but then when I call it:

> [theta, etta, lambda,

> gamma]=fminsearch(.matlab.todaysummary.com.m2,[theta0;etta0;lamb

da0;gamma0],opts);

> it gives me an error message saying that "Input argument 'theta' is

> undefined."

> am I misspecifying the fminsearch?

> thanks,

> olga

Assume that each vector has 5 elements

in it.

Then fminsearch will see a vector of 20

parameters. (Again, this is ludicrous.

Fminsearch is typically limited to

problems with maybe 6 unknowns in total.)

Fminsearch will try to optimize the

parameter space. But it will pass in a

SINGLE vector to M2, NOT 4 vectors.

Your function M2 needs to unpack the

vectors itself.

HTH,

John D'Errico

#1; Wed, 07 May 2008 18:01:00 GMT

- olga gorbachev wrote:
- Olga,
Syntax for m2() should be as follows:

function ll = m2(p)

where p - complete vector of parameters. You might also pass

additional arguments in fminsearch() and they will be passed into m2():

function ll = m2(p, data1, data2 ...)

Simplex method utilized by fminsearch() doesn't require derivatives

of m2() but if they exist a better algorithm can be used.

Hope it is help,

Kirill

olga gorbachev wrote:

> I have a question regarding runnign fminsearch with multiple

> parameters that are vectors themselves: theta etta lambda and gamma

> I define a function m2 as:

> function [min]=m2(theta, etta, lambda, gamma)

> but then when I call it:

> [theta, etta, lambda,

> gamma]=fminsearch(.matlab.todaysummary.com.m2,[theta0;etta0;lamb

da0;gamma0],opts);

> it gives me an error message saying that "Input argument 'theta' is

> undefined."

> am I misspecifying the fminsearch?

> thanks,

> olga

#2; Wed, 07 May 2008 18:02:00 GMT

- Olga,
- Kirill wrote:
>

> Olga,

> Syntax for m2() should be as follows:

> function ll = m2(p)

> where p - complete vector of parameters. You might also pass

> additional arguments in fminsearch() and they will be passed into

> m2():

> function ll = m2(p, data1, data2 ...)

> Simplex method utilized by fminsearch() doesn't require derivatives

> of m2() but if they exist a better algorithm can be used.

> Hope it is help,

> Kirill

> olga gorbachev wrote:

> gamma

'theta'

> is

>

Thank you all for replying. I still haven't been able to solve the

problem. I tried to use function handle, but I think I am misusing

it. I am new to Matlab and any help is greatly appreciated. This is

what I tried:

I have a function file new2.m where I have a system of equations (225

of them) to solve for 33 unkowns called theta. the problem, as i

already explained, is that 2 paraments within that theta are actually

fixed.

then I call this function from main.m where i specify an initial

vector of parameters

*******************

clear

load datag

tmin=1969; %the date of the first observation

tmax=1977; % the date of the last obs.

T=tmax-tmin+1;

bmin=1920; %first cohort is born in this year

bmax=1940; %last cohort is born in this year

B=((bmax-bmin)/5)+1; %the number of cohorts in the sample

zu1=zeros(1,9);

ro=1;

zu2=ones(1,2*T);

zu3=zeros(1,B);

theta0=[zu1 ro zu2 zu3]'; %initial parameter vector

p1969=1;

L1970=1;

M2 =

.matlab.todaysummary.com.new2:new2(theta0(1:10),p1969,theta0(12:

11+T),L1970,theta0(12+T+1:2*T+

10+B));

[theta fval]=fminsearch(M2,theta0,options);

**************

i know that line starting with M2 is wrong, but I dont' know how to

fix it. any ideas?

#3; Wed, 07 May 2008 18:03:00 GMT

- Kirill wrote: