MATLAB: How I put a vector (of integers) in a integral

matlab functionnumerical integration

I have this:
a= 5; b=3; c= 30.63; d= 37.49;
fun1 = @(t) (c-d)* (1+exp(-t./1)) + d;
fun2 = @(t) (c-d)* (1-exp(-t./11)) + d;
Tmed1= (1/Ton) * integral(fun1,0,a);
Tmed2= (1/Toff) * integral(fun2,0,b);
T_med_final= (a/(a+b))*c + (b/(a+b))*d;
I want to do something like this:
a=[1 2 3 4 5 6 7 8]
b=[5 6 7 8 7 6 5 4]
c=[5 4 3 2 1 0 -1 -2]
d=[8 7 6 5 4 3 2 1]
...
T_med_final(i)=.....
And then compute the T_med_final(i).
Is this possible?
Thank you.

Best Answer

It cannot be done simultaneously with integral(). Any one call to integral() needs scalar endpoints. You can use arrayfun() as a short hand for looping.
Tmed1 = 1/Ton + arrayfun(@(A,B,C,D) integral( @(t) (C-D)* (1+exp(-t./1)) + D, A, B), a, b, c, d)
Related Question