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:
quad function gets error "The integrand function must return an output vector of the same length as the input vector."

Subject: quad function gets error "The integrand function must return an output vector of the same length as the input vector."

From: Ozan

Date: 18 Mar, 2012 15:35:14

Message: 1 of 4

Hi all,

I couldn't find the reason of getting "The integrand function must return an output vector of the same length as the input vector." error while trying to compute integral. Below you will find my code:
My function 'part1' that computes the integrand:

function y = part1(cheb_epsilon);
y=diff(cheb_epsilon).*diff(cheb_epsilon);

Than I handle my function to quad, along with the limits of integration, -1 to 1:
    
Q=quad(@part1,-1,1)

After I run the code I get the following error
"??? Error using ==> quad at 80
The integrand function must return an output
vector of the same length as the input vector."

Could anyone tell me how can I handle this error?

Thanks

Subject: quad function gets error "The integrand function must return an output vector of the same length as the input vector."

From: Roger Stafford

Date: 18 Mar, 2012 17:00:12

Message: 2 of 4

"Ozan" wrote in message <jk4vbi$5ao$1@newscl01ah.mathworks.com>...
> Hi all,
>
> I couldn't find the reason of getting "The integrand function must return an output vector of the same length as the input vector." error while trying to compute integral. Below you will find my code:
> My function 'part1' that computes the integrand:
>
> function y = part1(cheb_epsilon);
> y=diff(cheb_epsilon).*diff(cheb_epsilon);
>
> Than I handle my function to quad, along with the limits of integration, -1 to 1:
>
> Q=quad(@part1,-1,1)
>
> After I run the code I get the following error
> "??? Error using ==> quad at 80
> The integrand function must return an output
> vector of the same length as the input vector."
>
> Could anyone tell me how can I handle this error?
>
> Thanks
- - - - - - - - - -
  It is not clear from your post whether you question the need for the input and output to be the same length or whether you question that they are not the same length as you have defined 'part1'.

  That they are not the same length is obvious from the fact that the 'diff' operation always reduces the length of a vector by one.

  That there is a need for them to be of the same length requires more explanation. You should realize that each element of the vector 'quad' sends to its function handle is a different value of the independent variable of that function. It is sending out parallel requests for a carefully chosen set of corresponding integrand values. Based on this it sends out other requests for sets of integrand values and continues this process until it is satisfied that it can give the integral to the required accuracy. If the function handle doesn't return the same number of integrand values to 'quad' then it doesn't know which independent variable values to associate with which integrand values. Its complaint in such a case is entirely justified.

Roger Stafford

Subject: quad function gets error "The integrand function must return an output vector of the same length as the input vector."

From: Roger Stafford

Date: 18 Mar, 2012 17:36:10

Message: 3 of 4

"Ozan" wrote in message <jk4vbi$5ao$1@newscl01ah.mathworks.com>...
> Hi all,
>
> I couldn't find the reason of getting "The integrand function must return an output vector of the same length as the input vector." error while trying to compute integral. Below you will find my code:
> My function 'part1' that computes the integrand:
>
> function y = part1(cheb_epsilon);
> y=diff(cheb_epsilon).*diff(cheb_epsilon);
>
> Than I handle my function to quad, along with the limits of integration, -1 to 1:
>
> Q=quad(@part1,-1,1)
>
> After I run the code I get the following error
> "??? Error using ==> quad at 80
> The integrand function must return an output
> vector of the same length as the input vector."
>
> Could anyone tell me how can I handle this error?
>
> Thanks
- - - - - - -
  I should also have pointed out that returning squares of difference values to 'quad' using 'diff' does not represent any kind of sensible integrand in the integration process. Even if it did somehow accept a reduced number of returned values, there is no way it could ever compute a valid integral from this. What would it be the integral of - the square of a derivative, but the derivative of what?

Roger Stafford

Subject: quad function gets error "The integrand function must return an output vector of the same length as the input vector."

From: Ozan

Date: 21 Mar, 2012 16:53:31

Message: 4 of 4


> - - - - - - -
> I should also have pointed out that returning squares of difference values to 'quad' using 'diff' does not represent any kind of sensible integrand in the integration process. Even if it did somehow accept a reduced number of returned values, there is no way it could ever compute a valid integral from this. What would it be the integral of - the square of a derivative, but the derivative of what?
>
> Roger Stafford

Thank you Roger for your interest.

I appreciate your answering my question.

Regards

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