COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Pass vector parameter into integration function?

• Follow

```Thanks to Torsten Hennig and Steve Lord for helping with the basic problem of passing parameters to integration functions (in previous question)

But can I pass a vector in?

In the code below, if I pass in a value of tau, e.g. tau=1, it works fine and I get the integral of the function between 0-1.

If I pass a vector of tau - it bombs out. (Even if I use meshgrid to make the right kind of data structure).

Is there a way? or do I have to do a VB type i=1:n loop and send in a value at a time?

===== code ========

function y = testfun(tau)
% function to test out integral of transmissivity using a nested function
% this works at the moment
% but I can only pass a single parameter, not a vector

function t=trans(x)

t = x.*exp(-tau./x);
end

end

===== end of code =====

Appreciate any help, thanks.
```
 0

```> Thanks to Torsten Hennig and Steve Lord for helping
> with the basic problem of passing parameters to
> integration functions (in previous question)
>
> But can I pass a vector in?
>
> In the code below, if I pass in a value of tau, e.g.
> tau=1, it works fine and I get the integral of the
> function between 0-1.
>
> If I pass a vector of tau - it bombs out. (Even if I
> use meshgrid to make the right kind of data
> structure).
>
> Is there a way? or do I have to do a VB type i=1:n
> loop and send in a value at a time?
>
> ===== code ========
>
> function y = testfun(tau)
> % function to test out integral of transmissivity
> using a nested function
> % this works at the moment
> % but I can only pass a single parameter, not a
> vector
>
>
>     function t=trans(x)
>
>         t = x.*exp(-tau./x);
>     end
>
> end
>
> ===== end of code =====
>
> Appreciate any help, thanks.

Are you aware of the fact that tau./x gives the
vector (tau(1)/x(1),...,tau(n)/x(n)) (assuming
tau and x have the same dimension) ?

You will have to pass the tau-values one-by-one
and call quadl in a corresponding for-loop.

Best wishes
Torsten.
```
 0

1 Replies
411 Views

Similiar Articles:

7/24/2012 6:29:22 PM