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:
Numerical gradient of K parameters for M-observations of a Nonlinear Regression model

Subject: Numerical gradient of K parameters for M-observations of a Nonlinear Regression model

From: Brian

Date: 5 Jan, 2012 15:20:08

Message: 1 of 3

Below is some code to manually evaluate the gradient of a nonlinear function of K parameters with this function defined over M observations. I run this and I get the following error message listed below:

k = length(betas);
dh = 1e-6; % **Values used in my manual gradients **
e = eye(k).*dh;
z=zeros(numobs,k);
for i=1:3;
        j=i;
        z(:,j) = (func_name(betas + e(:,j)) - func_name(betas - e(:,j)))./(2*dh); % ** Manual gradp **
     end

Error: "Subscript indices must either be real positive integers or logicals."

Any suggestions?

Subject: Numerical gradient of K parameters for M-observations of a Nonlinear

From: dpb

Date: 5 Jan, 2012 15:35:44

Message: 2 of 3

On 1/5/2012 9:20 AM, Brian wrote:
> Below is some code to manually evaluate the gradient of a nonlinear
> function of K parameters with this function defined over M observations.
> I run this and I get the following error message listed below:
>
> k = length(betas);
> dh = 1e-6; % **Values used in my manual gradients **
> e = eye(k).*dh;
> z=zeros(numobs,k);
> for i=1:3;
> j=i;
     z(:,j) = (func_name(betas + e(:,j)) - func_name(betas -
> e(:,j)))./(2*dh); % ** Manual gradp **
> end
>
> Error: "Subscript indices must either be real positive integers or
> logicals."
...

What's/where's func_name? Looks like Matlab thinks it's an array, not a
function.

Having the actual line on the error message would help...

--

Subject: Numerical gradient of K parameters for M-observations of a Nonlinear

From: dpb

Date: 5 Jan, 2012 19:07:27

Message: 3 of 3

On 1/5/2012 9:35 AM, dpb wrote:
> On 1/5/2012 9:20 AM, Brian wrote:
>> Below is some code to manually evaluate the gradient of a nonlinear
>> function of K parameters with this function defined over M observations.
>> I run this and I get the following error message listed below:
>>
>> k = length(betas);
>> dh = 1e-6; % **Values used in my manual gradients **
>> e = eye(k).*dh;
>> z=zeros(numobs,k);
>> for i=1:3;
>> j=i;
> z(:,j) = (func_name(betas + e(:,j)) - func_name(betas -
>> e(:,j)))./(2*dh); % ** Manual gradp **
>> end
>>
>> Error: "Subscript indices must either be real positive integers or
>> logicals."
> ....
>
> What's/where's func_name? Looks like Matlab thinks it's an array, not a
> function.
>
> Having the actual line on the error message would help...

OBTW, it's not the problem here but in general one will be best served
to not use 'i' or 'j' as indices in Matlab despite the propensity in
other languages. By default they're defined as the complex i,j and
overloading them can/will cause grief some time when you really do want
complex numbers...

--

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