Thread Subject:
Error using Quad

Subject: Error using Quad

From: Jimmy Varghese

Date: 21 Jul, 2012 17:32:16

Message: 1 of 3

Hi All,

I am seeing the following error using quad.
quad(@myfun2, 0,0.3,[],1)
??? Input argument 'iii' is undefined.

Here is my function

function phi = myfun2(x,iii)


n = 6;
L=0.3;
cal=5;
ii=1;
while ii< n+1
    mu(ii)=cal*pi/4;
    cal=cal+4;
      ii=ii+1;
end




for i = 1:n
    N(i) = sqrt(L)*(sqrt(abs(cos(mu(i))*cosh(mu(i))-1)*abs(2*sin(mu(i))*sinh(mu(i)))))/abs(cos(mu(i))-cosh(mu(i)));
end


phi = (1./N(iii))*((sin(mu(iii))-sinh(mu(iii)))./(cos(mu(iii))-cosh(mu(iii)))*(cos(mu(iii)*x/L)-cosh(mu(iii)*x/L))-(sin(mu(iii)*x/L)-sinh(mu(iii)*x/L)));

Subject: Error using Quad

From: Torsten

Date: 23 Jul, 2012 06:33:43

Message: 2 of 3

On 21 Jul., 19:32, "Jimmy Varghese" <jimmyvarghe...@gmail.com> wrote:
> Hi All,
>
> I am seeing the following error using quad.
> quad(@myfun2, 0,0.3,[],1)
> ??? Input argument 'iii' is undefined.
>
> Here is my function
>
> function phi = myfun2(x,iii)
>
> n = 6;
> L=0.3;
> cal=5;
> ii=1;
> while ii< n+1
> mu(ii)=cal*pi/4;
> cal=cal+4;
> ii=ii+1;
> end
>
> for i = 1:n
> N(i) = sqrt(L)*(sqrt(abs(cos(mu(i))*cosh(mu(i))-1)*abs(2*sin(mu(i))*sinh(mu(i)))))/abs(cos(mu(i))-cosh(mu(i)));
> end
>
> phi = (1./N(iii))*((sin(mu(iii))-sinh(mu(iii)))./(cos(mu(iii))-cosh(mu(iii)))*(cos(mu(iii)*x/L)-cosh(mu(iii)*x/L))-(sin(mu(iii)*x/L)-sinh(mu(iii)*x/L)));

iii=1;
a=0;
b=0.3;
q=quad(@(x)myfun2(x,iii),a,b);


function phi = myfun2(x,iii)
...


Best wishes
Torsten.

Subject: Error using Quad

From: Steven_Lord

Date: 23 Jul, 2012 13:56:46

Message: 3 of 3



"Torsten" <Torsten.Hennig@umsicht.fraunhofer.de> wrote in message
news:fde07635-c8c2-423f-9ad2-e0753a132115@fi17g2000vbb.googlegroups.com...
> On 21 Jul., 19:32, "Jimmy Varghese" <jimmyvarghe...@gmail.com> wrote:
>> Hi All,
>>
>> I am seeing the following error using quad.
>> quad(@myfun2, 0,0.3,[],1)
>> ??? Input argument 'iii' is undefined.
>>
>> Here is my function
>>
>> function phi = myfun2(x,iii)
>>
>> n = 6;
>> L=0.3;
>> cal=5;
>> ii=1;
>> while ii< n+1
>> mu(ii)=cal*pi/4;
>> cal=cal+4;
>> ii=ii+1;
>> end
>>
>> for i = 1:n
>> N(i) =
>> sqrt(L)*(sqrt(abs(cos(mu(i))*cosh(mu(i))-1)*abs(2*sin(mu(i))*sinh(mu(i)))))/abs(cos(mu(i))-cosh(mu(i)));
>> end
>>
>> phi =
>> (1./N(iii))*((sin(mu(iii))-sinh(mu(iii)))./(cos(mu(iii))-cosh(mu(iii)))*(cos(mu(iii)*x/L)-cosh(mu(iii)*x/L))-(sin(mu(iii)*x/L)-sinh(mu(iii)*x/L)));
>
> iii=1;
> a=0;
> b=0.3;
> q=quad(@(x)myfun2(x,iii),a,b);
>
>
> function phi = myfun2(x,iii)

Torsten described the approach I'd recommend you use. The reason that what
you tried did NOT work is because you were trying to use an older syntax for
QUAD but you didn't use it correctly. QUAD used to (and still does, for
compatibility) accept additional parameters after the TRACE input and pass
those additional parameters to the integrand function. But those additional
parameters needed to be the 6th and later inputs to QUAD; what you specified
is that you wanted to integrate myfun2 from a = 0 to b = 0.3 with the
default tolerance and with tracing turned on. Since you didn't specify any
additional parameters, QUAD called your function with ONE input argument.

Again, while you _could_ fix this by specifying an extra [] in your QUAD
call, I'd recommend using Torsten's anonymous function adapter approach or
one of the other approaches described in this page from the documentation:

http://www.mathworks.com/help/techdoc/math/bsgprpq-5.html

Newer "function functions" like QUADGK/INTEGRAL/etc. do NOT have that
"trailing additional parameters" syntax as an option, so if you were
planning to eventually use QUADGK or INTEGRAL instead of QUAD you'd need to
update your code anyway.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
quad error Jimmy Varghese 21 Jul, 2012 13:34:37
rssFeed for this Thread

Contact us