Hi everyone!
I'm having some trouble trying to plot streamlines of a field I'm using in a code. It is a 3D field whose components are represented by 3 functions (Bx,By,Bz) I defined.
I'm interested in plotting the streamlines of the field into a 3D thoroidal volume but I don't really have a clue about the right way to do this; I tried to use this code but it doesn't work.
Babs=5;
R0=0.1; %major R
r0=linspace(0,0.005,3); %inner R
th=linspace(0,2*pi,20); %poloidal angle
phi=linspace(0,2*pi,30); %thoroidal angle
[Phi,Th,rr0]=meshgrid(phi,th,r0);
xx=(R0+rr0.*cos(Th)).*cos(Phi);
yy=(R0+rr0.*cos(Th)).*sin(Phi);
zz=rr0.*sin(Th);
[starty,startz]=meshgrid(yy,zz);
streamline(xx,yy,zz,Bx(Babs,xx,yy,zz,R0),By(Babs,xx,yy,zz,R0),Bz(Babs,xx,yy,zz,R0),starty.*0,starty,startz);
%definisco le funzioni per il campo B
function a1 = Bx(Babs,x,y,z,R0)
RR=sqrt(x.^2+y.^2);
a1=R0.*Babs.*(-1.*sin(atan2(y,x)))./RR;
end
function b1 = By(Babs,x,y,z,R0)
RR=sqrt(x.^2+y.^2);
b1=R0.*Babs.*(cos(atan2(y,x)))./RR;
end
function c1 = Bz(Babs,x,y,z,R0)
c1=Babs.*x.*0;
end
the error I get is
Error using griddedInterpolant
The grid vectors must contain unique points.
I'm also not sure about what way would be the best to define startx, starty and startz in this case.
Thanks in advance for everyone who will try to help me!

 채택된 답변

darova
darova 2019년 9월 11일

1 개 추천

I used quiver3
export_fig_out.png
Can't you just draw circles if it is that straight?

댓글 수: 4

Massimo Carpita
Massimo Carpita 2019년 9월 11일
편집: Massimo Carpita 2019년 9월 11일
Dear darova, thank you for your answer!
I tried to use quiver but I would like to plot streamlines because it would be more suitable for my purpose.
You're actually right, in the code I posted my streamlines would look like circles but that is not the only field I need to plot! Other fields have a more complicated geometry.
darova
darova 2019년 9월 12일
I wrote a simple script for streamlines
As you can see it's not that accurate as i wanted it to be
(it also depends on number of points for one streamline)
img1.png
c1 (nz) vector modificated (looks like russian tokamak)
img2.png
See the script i attached
darova
darova 2019년 9월 12일
Algorithm of the script as on the picture:
21Untitled.png
Since you know the vector field a new position of a points can be calculated
Dear Darova, for my purpose this will do!
Thank you very much again :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Vector Fields에 대해 자세히 알아보기

질문:

2019년 9월 11일

댓글:

2019년 9월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by