Plotting a velocity vector field

조회 수: 29 (최근 30일)
Talha Yagli
Talha Yagli 2023년 1월 7일
댓글: Talha Yagli 2023년 1월 7일
I am trying to plot a velocity vector filed that taken from the user as an input
syms x y z i j k
velocity=(input("velocity:","s")) %example (x^2+y*z)*i+((z^3)*4*y)*j+(y^2)*k
convertCharsToStrings(velocity);
velocity_eq=inline(velocity,"x","y","z","i","j","k");
velocity_iComp=symfun(velocity_eq(x,y,z,1,0,0),[x,y,z]); % these are i j k componenets of the vector
velocity_jComp=symfun(velocity_eq(x,y,z,0,1,0),[x,y,z]);
velocity_kComp=symfun(velocity_eq(x,y,z,0,0,1),[x,y,z]);
that is how ı get the vector field equation from the user
lenghtV=sqrt(velocity_iComp.^2+velocity_jComp.^2+velocity_kComp.^2) % lenght formula of each vector on field
how can ı plot this symbolic vector field equation
  댓글 수: 2
Paul
Paul 2023년 1월 7일
syms x y z i j k
%velocity=(input("velocity:","s")) %example (x^2+y*z)*i+((z^3)*4*y)*j+(y^2)*k
velocity = '(x^2+y*z)*i+((z^3)*4*y)*j+(y^2)*k';
velocity = convertCharsToStrings(velocity);
velocity_eq=inline(velocity,"x","y","z","i","j","k");
velocity_iComp=symfun(velocity_eq(x,y,z,1,0,0),[x,y,z]); % these are i j k componenets of the vector
velocity_jComp=symfun(velocity_eq(x,y,z,0,1,0),[x,y,z]);
velocity_kComp=symfun(velocity_eq(x,y,z,0,0,1),[x,y,z]);
lenghtV=sqrt(velocity_iComp.^2+velocity_jComp.^2+velocity_kComp.^2) % lenght formula of each vector on field
lenghtV(x, y, z) = 
We have a scalar function of 3 variables. How would you like to visualize this function? This doc page may be a good place to start.
Talha Yagli
Talha Yagli 2023년 1월 7일
I'd like to achive a something like this. Also the equation above is a vector;
(example)
Basicly it is a 3 variable vector field equation, my purpose is to plot this symblolic equation

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

채택된 답변

Paul
Paul 2023년 1월 7일
Here is how you can plot what I thinkg your want using quiver3 over a 3D cube. Should be able to adapt it as needed. Check its doc page or this one or the one linked above for more details and other options.
syms x y z i j k
%velocity=(input("velocity:","s")) %example (x^2+y*z)*i+((z^3)*4*y)*j+(y^2)*k
velocity = '(x^2+y*z)*i+((z^3)*4*y)*j+(y^2)*k';
velocity = convertCharsToStrings(velocity);
velocity_eq=inline(velocity,"x","y","z","i","j","k");
velocity_iComp=symfun(velocity_eq(x,y,z,1,0,0),[x,y,z]) % these are i j k componenets of the vector
velocity_iComp(x, y, z) = 
velocity_jComp=symfun(velocity_eq(x,y,z,0,1,0),[x,y,z])
velocity_jComp(x, y, z) = 
velocity_kComp=symfun(velocity_eq(x,y,z,0,0,1),[x,y,z])
velocity_kComp(x, y, z) = 
icomp = matlabFunction(velocity_iComp,Vars = {'x' 'y' 'z'})
icomp = function_handle with value:
@(x,y,z)y.*z+x.^2
jcomp = matlabFunction(velocity_jComp,Vars = {'x' 'y' 'z'})
jcomp = function_handle with value:
@(x,y,z)y.*z.^3.*4.0
kcomp = matlabFunction(velocity_kComp,Vars = {'x' 'y' 'z'})
kcomp = function_handle with value:
@(x,y,z)y.^2
[X,Y,Z] = meshgrid(0:.2:1,0:.2:1,0:.2:2);
U = icomp(X,Y,Z);
V = jcomp(X,Y,Z);
W = kcomp(X,Y,Z);
quiver3(X,Y,Z,U,V,W)
xlabel('X'),ylabel('Y'),zlabel('Z')
  댓글 수: 1
Talha Yagli
Talha Yagli 2023년 1월 7일
Thank you very much for your attention I have been working on this for days

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by