我需要帮助在 MATLAB 中以笛卡尔坐标绘制球面方程 [英] I need help graphing a spherical equation in Cartesian coordinates in MATLAB

查看:42
本文介绍了我需要帮助在 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Φ)

产生如下所示的内容:

我想在一个 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

我得到了以下图表:

为什么会这样?为什么我没有得到计算课本显示的凹凸不平的球体?

Why is this happening? Why am I not getting the bumpy sphere my calc textbook shows?

推荐答案

有两个问题:

  1. 您需要在 sin(6*t) 和 sin(5*q) 之间使用 .* 而不是 *,因为您想要按元素乘法而不是矩阵乘法.

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆