Loop these vectors into an array?
显示 更早的评论
I have a function that needs to be integrated.
int = @(x)(1+0.25*sin((P/5)*x*sin(AngRad)+(P/4))).*exp(-1i*2.*x.*cos(AngRad).*K(1));
q01 = integral(int,-L/2,L/2,'ArrayValued',true);
int = @(x)(1+0.25*sin((P/5)*x*sin(AngRad)+(P/4))).*exp(-1i*2.*x.*cos(AngRad).*K(2));
q02 = integral(int,-L/2,L/2,'ArrayValued',true);
%this goes on 35 more times
The value "P" is pi just with more digits, "AngRad" is a 721x1 vector of angles 0-360 degrees in radians, and "K" is originally a 37x1 vector of wave numbers. My goal is to find a way to loop (or some other way) the function and the integral so that I don't have to have 37 different "q01" to form my ultimate matrix which is a 721x37 matrix, a combination of the AngRad and K vectors. How and what is the best way to go about this and save computation time?
采纳的回答
更多回答(1 个)
Walter Roberson
2016-2-17
tic;
P = 3.14159265358979323846264338328;
AngRad = linspace(0,2*pi,721);
K = round(linspace(380,650,37));
L = sqrt(1/5); %for lack of better value
[RadR, KR] = ndgrid(AngRad, K);
int = @(x) (1+0.25.*sin((P/5).*x.*sin(RadR)).*(exp(-1i.*2.*x.*cos(RadR).*KR)));
q = integral(int, -L/2,L/2, 'ArrayValued', true);
toc
size(q)
Elapsed time is 1.986690 seconds.
ans =
721 37
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!