2015-10-02 23 views
0

我在scilab中编写了下面的代码,并且想要绘制它,但情节看起来不像3D。基本上问题是尺寸,x和y是1个交叉5矩阵,函数f是5个交叉矩阵。我试图通过使用meshgrid来制作x和y 5维,但是这些函数无法给我带来修改后的meshgrid(x,y)值。整个代码在这里。感谢有人帮助我。三维绘图中的尺寸isue

clear; clc; 
//Defining the range of Cartesian coordinates (x,y,z) 
x = linspace(1,30,5); 
y = linspace(0,30,5); 
z = linspace(0,30,5); 
//------------------------------------------------------------------------------ 
//This funciton transform Cartesian to Spherical coordinates 
function [r, theta, phi]=cart2sph(x, y, z) 
    r = sqrt(x^2+y^2+z^2); 
    theta = atan(y./x) 
    phi = acos(z./sqrt(x^2+y^2+z^2))' 
endfunction 
//------------------------------------------------------------------------------ 
//To get the spherical coordinates from Cartesian uing the above funciton 
[r, theta, phi]=cart2sph(x, y, z) 
//------------------------------------------------------------------------------ 
//Defining spherical hormonic as a funciton of shperical coordinates here. 
function [y]=Y(l, m, theta, phi) 
    if m >= 0 then 
    y = (-1)^m/(sqrt(2*%pi))*exp(%i*m*phi)*legendre(l, m, cos(theta), "norm") 
    else 
    y = 1/(sqrt(2*%pi))*exp(%i*m*phi)*legendre(l, -m, cos(theta), "norm") 
    end  
endfunction 
l = 1; m = -1; 
f = Y(l,m,theta,phi); 
//I got the funciton value in spherical coordinates and 
//that spherical coordinates are funciton of Cartesian coordinates. 
//So basically funciton Y is a funciton of Cartesian coordinates (x,y,z). 
//Next to plot funciton Y against (x,y) 
//------------------------------------------------------------------------------ 
clf(); 
plot3d(x,y,f,flag=[2 4 4]); xtitle("|Y31(x,y)|"); 

回答

0

你的问题是由于f的范围,这是非常小的x和y的比较。为了得到你期望的结果,你可以按照如下步骤进行: plot3d(x,y,f,flag = [2 4 4]); xtitle( “| Y31(X,Y)|”); ax = gca(); ax.cube_scaling =“on”;

+0

谢谢先生。是工作 –