Vectorizing parameterized integral function...bsxfun or arrayfun or meshgrid ?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have a function calculating an integral with several parameters ; I'd like to vectorize it but have a problem in doing so :
function bz=fonc(a,b1,b2,ri,p1,p2,x,y,z)
bz=0.d0;
arot=atan2(y,x);
rro=sqrt(x.^2+y.^2);
p1i=p1.*pi-arot;
p2i=p2.*pi-arot;
bi=0.5d0.*(b2-b1);
bmi=0.5d0.*(b1+b2);
zi=z-bmi;
b1i=-bi-zi;
b2i=bi-zi;
%
fact=0.5d-7.*ri./bi;
re2=quadgk(@(x) fuz(x,b1i,b2i,a,rro),p1i,p2i);
bz=fact.*re2.*a;
end
function zf=fuz(tet,z1,z2,a,ro)
zf=((a-ro.*cos(tet))./(a.^2+ro.^2-2.*a.*ro.*cos(tet))).* ...
(z2./sqrt(a.^2+ro.^2+z2.^2-2.*a.*ro.*cos(tet))-z1./sqrt(a.^2+ro.^2+z1.^2-2.*a.*ro.*cos(tet)));
end
The function computes the field of an inductor described by a,b1,b2,ri,p1,p2 at the point x,y,z.
I have to compute the field at n points (x(i),y(i),z(i) i=1:n) with m inductors (a(j),b1(j),b2(j),ri(j),p1(j),p2(j) j=1:m) and do no find a proper solution using arrayfun or bsxfun or meshgrid. Of course, i want to avoid nested for loops.
I'd like to vectorize it with a,b1,b2,ri,p1,p2, vectors of same length and x, y, z vectors of same length.
Cheers.
FP
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!