I need help graphing a spherical equation in Cartesian coordinates in MATLAB

筅森魡賤 提交于 2019-12-12 06:20:06

问题


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:

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

And I got the following graph:

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


回答1:


There are two problems:

  1. You need .* rather than * between your sin(6*t) and sin(5*q) since you want per element multiplication not matrix multiplication.

  2. 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



来源:https://stackoverflow.com/questions/30089707/i-need-help-graphing-a-spherical-equation-in-cartesian-coordinates-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!