help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Integration with quad


From: Jaroslav Hajek
Subject: Re: Integration with quad
Date: Thu, 10 Dec 2009 07:12:26 +0100

On Wed, Dec 9, 2009 at 10:07 PM, David Bateman <address@hidden> wrote:
> address@hidden wrote:
>> -----Original Message-----
>> From: Søren Hauberg [mailto:address@hidden
>>
>> ons, 09 12 2009 kl. 20:07 +0100, skrev Thomas Göbel:
>>
>>>> i want to integrate the following function:
>>>>
>>>> function y = rect(t)
>>>> if t<=0.5
>>>>     rect=1
>>>> else
>>>>     rect=0
>>>> end
>>>> endfunction
>>>>
>>
>>
>>> Your return value is called 'y', but you never define this in your
>>> function. Try something like
>>>
>>> function y = rect(t)
>>>  if t<=0.5
>>>    y=1
>>>  else
>>>    y=0
>>>  endif
>>> endfunction
>>>
>>
>> You can also write:
>>
>> function y = rect(t)
>>   y = (t<=0.5);
>> endfunction
>>
>> This function will work on a vector.  Are there methods to "vectorize" other 
>> functions with less tractable conditional statements?
>>
>> Regards,
>> Allen
>>
> Yes quadgk or quadv is what you are looking for.. It also has another
> advantage in that it handles infinite limits, boundary singularities and
> you can define point of discontinuities in the function or its derivatives
> with the "WayPoints" options (if you know them) like
>
> quadgk ('rect', -1, 2, 'WayPoints', 0.5)
>
> Also, using an anonymous function handle like
>
> quadgk(@(x) rect(x), -1, 2, 'WayPoints', 0.5)
>
> will certainly be faster in the development sources, though probably not
> in 3.2
>
> D.

Even better is to pass just @rect. That way the extra overhead of the
anonymous function is completely avoided.
I already started to implement an optimization for simple cases like
@(x) myfun (x, param), but I hit some issues, so I've put it off until
after 3.4.

just my 2cts

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]