我需要在MATLAB的笛卡尔坐标中绘制球面方程的帮助 [英] I need help graphing a spherical equation in Cartesian coordinates in MATLAB
问题描述
我知道函数sph2cart
,但是我觉得我一定在错误地使用它.在微积分教科书中,我看到了下面的球面方程:
I know about the function sph2cart
, but I feel like I must be using it wrong. In a Calculus textbook, I saw that this following spherical equation:
ρ = 1 + 1/5*sin(6θ)*sin(5Φ)
产生的东西看起来像这样:
produces something that looks like this:
我想在Matlab图形中重现它,所以我编写了以下代码
I wanted to reproduce this in a Matlab graph, so I wrote the following code
[q,t] = meshgrid(linspace(0,pi,100),linspace(0,2*pi,100));
rho = 1+1/5*sin(6*t)*sin(5*q);
[x,y,z] = sph2cart(t,q,rho);
surf(x,y,z)
axis square, axis equal
我得到了下图:
为什么会这样?为什么我的calc教科书无法显示颠簸的球面?
Why is this happening? Why am I not getting the bumpy sphere my calc textbook shows?
推荐答案
有两个问题:
-
在sin(6 * t)和sin(5 * q)之间需要.*而不是*,因为您希望每个元素的乘法而不是矩阵乘法.
You need .* rather than * between your sin(6*t) and sin(5*q) since you want per element multiplication not matrix multiplication.
您希望q从0-PI运行,并且t从0-2PI运行
You want q to run from 0-PI and t to run from 0-2PI
此代码产生您想要的结果.
This code produces the result you're looking for.
[q,t] = meshgrid(linspace(0,2*pi,100),linspace(0,pi,100));
rho = 1+(1/5*sin(6*t).*sin(5*q));
[x,y,z] = sph2cart(t,q,rho);
surf(x,y,z)
axis square, axis equal
这篇关于我需要在MATLAB的笛卡尔坐标中绘制球面方程的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!