How to vectorize integral?
Show older comments
h=0.1;
t1=0:h:2*pi;
alpha=0.3;
f=@(x) sin(x);
for i=2:length(t1)
t=t1(i);
k=1/gamma(1-alpha);
w=@(s) (t-s).^(-alpha).*cos(s);
p(i)=integral(w,0,t);
end
1 Comment
TheStranger
on 1 Sep 2017
Hello Sameer. Sorry for the offtop, but have you tested, whether a vectorized version is faster than just looping? I tried "integral" function with "ArrayValued=1" and it turned out that it is 20% slower than just looping over the parameter, for example.
Accepted Answer
More Answers (1)
Andrei Bobrov
on 6 Aug 2017
Edited: Andrei Bobrov
on 6 Aug 2017
h=0.1;
t1=0:h:2*pi;
p = arrayfun(@(t)integral(@(s)(t-s).^-alpha.*cos(s),0,t),t1)
1 Comment
Sameer Chikane
on 8 Aug 2017
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!