Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: quad function gets error "The integrand function must return an output vector of the same length as the input vector."
Date: Sun, 18 Mar 2012 17:00:12 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <jk54as$ij5$1@newscl01ah.mathworks.com>
References: <jk4vbi$5ao$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1332090012 19045 172.30.248.37 (18 Mar 2012 17:00:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 18 Mar 2012 17:00:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:761368

"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