Vectorizing parameterized integral function...bsxfun or arrayfun or meshgrid ?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!