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)
I made it work. 

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

y=quadl(@trans,0,1);

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

end

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

Appreciate any help, thanks.
0
Reply Peter 2/4/2011 11:12:03 PM

> Thanks to Torsten Hennig and Steve Lord for helping
> with the basic problem of passing parameters to
> integration functions (in previous question)
> I made it work. 
> 
> 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
> 
> y=quadl(@trans,0,1);
> 
>     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
Reply Torsten 2/5/2011 6:32:49 AM


1 Replies
411 Views

(page loaded in 0.041 seconds)

Similiar Articles:













7/24/2012 6:29:22 PM


Reply: