help-octave
[Top][All Lists]

 From: David Bateman Subject: Re: Integration with quad Date: Wed, 09 Dec 2009 22:07:11 +0100 User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706)

```address@hidden wrote:
```
```-----Original Message-----
```
```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.

```