taking maximum of multiple functions
3 views (last 30 days)
Show older comments
Hi!
I created an 'expspectrum' function that I am using in another file (see below). I am using this function in another file like this:
B=100;
D=100;
s_b=440;
s_e=510;
s_bb=290;
s_ee=430;
s_bbb=70;
s_eee=120;
I=@(t)max(expspectrum(t,s_b,s_e,D,B),expspectrum(t,s_bb,s_ee,D,B));
integral(I,0,max(s_e,s_ee))
fplot(I,[0 700])
so my goal is to calculate this integral. My question is how can I take the maximum of more than 2 'expspectrums' and integrate them (would love to plot them as well). simply extending 'I' as this doesn't work:
I=@(t)max(expspectrum(t,s_b,s_e,D,B),expspectrum(t,s_bb,s_ee,D,B),expspectrum(t,s_bb,s_ee,D,B));
In the end I want calculate this integral for an undefined number of expspectrums: i.e. I have a matrix with n (unknown) pairs of (s_b, s_e), I want to 'create' and expspectrum for each pair, take the maximum of these exspectrums and than take the integral.
function y=expspectrum(t,a,b,D,B)
if a<0
s_b=0;
else
s_b=mod(a,D);
end
l=b-a;
if t<=0
y=0;
else
if t < a
y=1-exp(-max(D*(ceil((t-s_b)/D)-(t-s_b)/D)-(D-l),0)/B);
else
if t < b
y=1-exp(-(l-(t-a))/B);
else
y=0;
end
end
end
bonus question: any tips on making this as fast as possible (both expspectrum function and the calculation of the integral), will use this in simulation.
Thanks!
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!