Loop these vectors into an array?
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 17 Fév 2016
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
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!