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)
%------------------------------------

댓글 수: 1

Kobye
Kobye 2013년 7월 21일
It would be helpful if you could explain why you need this code to run faster? On my pc it runs in 1.163567 seconds.
It seems highly unlikely that you are trying to generate 1 million plots in a loop. What is the benefit of further speeding up this already fast piece of code?

댓글을 달려면 로그인하십시오.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 7월 21일
편집: Andrei Bobrov 2013년 7월 21일

0 개 추천

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;

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by