Plot of the function after integration

Hello. I want to plot a complicated function. Unfortunately at the end I obtain just one point of the function and the empty graph. I'd like to avoid exploitation of the command for to speed up my calculations. Could you explain where is my mistake? Thank you. Below is my code
function z=test_plot
tic
tt=-0.000689609;t=0.242731; muu=0.365908;
[m,NN]=meshgrid(0:100,-3000:1:3000);
y1= @(N,q,k) t*q./k.*log((-k.^2+2*k.*q-q.^2+muu+1i*(2*pi*N.*t-(2*m(1,:)+1)*pi*t))./(-k.^2-2*k.*q-...
q.^2+muu+1i*(2*pi*N.*t-(2*m(1,:)+1)*pi*t)))./(tt*pi+integral(@(a)a.*tanh((a.^2-muu)./(2*t)).*log((2*a.^2+2*a.*q+...
q.^2-2*muu-1i*2*pi*N*t)./(2*a.^2-2*a.*q+q.^2-2*muu-1i*2*pi*N*t))./q-2,0,10000,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true));
R1=@(q,k) integral(@(N)y1(N,q,k),3000,10^6,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true);
R11=@(q,k) integral(@(N)y1(N,q,k),-10^6,-3000,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true);
y2=@(q,k) t*q./k.*log((-k.^2+2*k.*q-q.^2+muu+1i*(2*pi*NN(:,1).*t-(2*m(1,:)+1)*pi*t))./(-k.^2-2*k.*q-...
q.^2+muu+1i*(2*pi*NN(:,1).*t-(2*m(1,:)+1)*pi*t)))./(tt*pi+integral(@(a)a.*tanh((a.^2-muu)./(2*t)).*log((2*a.^2+2*a.*q+...
q.^2-2*muu-1i*2*pi*NN(:,1).*t)./(2*a.^2-2*a.*q+q.^2-2*muu-1i*2*pi*NN(:,1).*t))./q-2,0,10000,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true));
R2=@(q,k) sum(y2(q,k));
S=@(q,k) R1(q,k)+R11(q,k)+R2(q,k)-4*sqrt(2)/pi*(1/1000)/(pi^(3/2)*sqrt(t))*q.^2;
Sigma=@(k) integral(@(q)S(q,k),0.001,7,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true);
Sum_sigma=@(k) 2*real(sum(Sigma(k)./((1i*(2*m(1,:)+1)*pi*t-k.^2+muu-Sigma(k)).*(1i*(2*m(1,:)+1)*pi*t-k.^2+muu))));
k=0.001:0.05:5.01;
Sum_sigma(k)
plot(k,Sum_sigma(k))
toc
end

12 件のコメント

Torsten
Torsten 2018 年 10 月 12 日
Sum_Sigma(k) is a single value since you sum over Sigma(k).
Yuriy Yerin
Yuriy Yerin 2018 年 10 月 12 日
Thanks for the response. I agree with you but I expected to get an array with the values of the function Sum_sigma as I introduced array for k.
Torsten
Torsten 2018 年 10 月 12 日
編集済み: Torsten 2018 年 10 月 12 日
Yes, and it is the (transformed) array k that is summed over.
Yuriy Yerin
Yuriy Yerin 2018 年 10 月 12 日
Finally, I got it! But my goal is the summation over m(1,:) for each value of k. Anyway thanks for the clarification. I will think about modification of the code.
Torsten
Torsten 2018 年 10 月 12 日
編集済み: Torsten 2018 年 10 月 12 日
Note that the summation only works because m(1,:) and k have the same number of elements. This already suggests that something must be wrong with your code.
Yuriy Yerin
Yuriy Yerin 2018 年 10 月 12 日
The code works correctly until the calculation of the function Sum_sigma(k). I plotted this function via loop
k=linspace(0.001,6,60)
for l=1:60
R(l)=Sum_sigma(k(l));
end
plot(k,R)
But it took a lot of time. So I wanted just to speed up the code using such approach.
Torsten
Torsten 2018 年 10 月 12 日
k = 0.001:0.05:5.01;
S = arrayfun(Sum_sigma,k);
plot(k,S)
Yuriy Yerin
Yuriy Yerin 2018 年 10 月 12 日
A lot of thanks! I forgot about arrayfun. Have a nice day!
Torsten
Torsten 2018 年 10 月 15 日
編集済み: KSSV 2018 年 10 月 15 日
But it doesn't save time in comparison to the for-loop, does it ?
Maybe this could help to speed up your calculations:
Yuriy Yerin
Yuriy Yerin 2018 年 10 月 15 日
Yes, it does. Unfortunately (for me) you are right. Thank for the reference. You mean that I have to try the command gpuArray(k) ?
Torsten
Torsten 2018 年 10 月 15 日
I have no experience with parallel computing in MATLAB. But since the calculations for different k-values are independent, it should somehow be possible to parallelize here.
Yuriy Yerin
Yuriy Yerin 2018 年 10 月 15 日
Me too, but anyway thank you again for the help. I will google about that.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePerformance and Memory についてさらに検索

質問済み:

2018 年 10 月 12 日

コメント済み:

2018 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by