MATLAB: How to make the code runs faster

integrationruns slow

Hello,
I programmed this integration but the output results and the plot require some time. Do you have any ideas to change in the code to make it run faster?!!
Thanks
%--------------------------
clear, clc, clf
syms s
x=-3:0.01:3;
for i=1:length(x)
integ=@(s) sin(s).*cos(s*x(i))./s;
ST(i)=2*quad(integ,0,12)/pi;
end
plot(x,ST,'Color','k','LineWidth',3.5)
%------------------------------------

Best Answer

x=-3:0.01:3;
ST = 2*quadv(@(s) sin(s).*cos(s*x)./s,0,12)/pi;
or
x=-3:0.01:3;
ST = integral(@(s) sin(s).*cos(s*x)./s,0,12,'ArrayValued',true)*2/pi;
Related Question