Integrate the product of a symbolic array

2 views (last 30 days)
I need to integrate the following equation; R(t) = e^-(t/x)^y. For the variables x and y, I have an array of [n,2], where x and y are known numbers. For every n, I need the integral to update to integral(R1(t)*R2(t)*Rn(t))dt. My first thought was loop through all the x's and y's, to create an array of symbolic equations, then integrate the product of the array. Are there any better methods of multiplying another R(t) to the integrand for every n? I could use the reimann sum method, but I'd like to know why my code blows up with a symbolic issue.
I've tried various approaches to this method and am running into the following errors:
1. Input function must return 'double' or 'single' values. Found 'sym'.
2. DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use VPA.
3. First input argument must be a function handle.
Below is a rough segment of my code with example x and y.
x = [5000 10000 25000];
y = [1 2.5 3]
n = length(x); %Determine number of entries to loop thru
func = sym('t',[1, 2]); %Pre-allocating memory
for i = 1:n
func(i) = @(t) exp(-(t./x(i)).^y(i));
end
integrand = @(t) prod(func); %Here I want the integrand to become the product of func, such that I now have R1(t)*R2(t)*Rn(t). Do I need another @(t) here?
solution = integral(integrand,0,inf);
At this point, I know the prod(func) = exp(-t/5000) * exp(-(t/10000)^(5/2)) * exp(-t^3/15625000000000), which is what I want. Now I should be able to throw this into the integral function, but I get the aforementioned errors. Any help is appreciated.

Answers (1)

Walter Roberson
Walter Roberson on 29 Jul 2015
integrand = @(t) prod(func(t));
However instead of your loop, you should just code
integrand = prod(exp(-(t./x(K)).^y(K), K, 1, n);
Then
solution = double( int(integrand, t, 0, inf) ); %symbolic computation then numeric eval
or
solution = integral(matlabFunction(integrand,t),0, inf); %numeric computation

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!