Linspace and polar coordinates

5 ビュー (過去 30 日間)
Danny Allen
Danny Allen 2021 年 3 月 12 日
コメント済み: Star Strider 2021 年 3 月 13 日
Hello.
I'm a little lost when it comes to using polar coordinates in matlab. How would I set up a linspace for polar coordinates? I'm also unsure of what the best method is for plotting in polar, should I use the polar command?
I've been using the code below but keep recieving an error.
x=[-2 -1 0 1 2];
y=[-2 -1 0 1 2];
%cartesian --> polar
rho=sqrt(x.^2+y.^2);
theta=atan(y./x);
%set up linspace with 10 pts
rho2=linspace(rho,rho,10) %this is where I'm confused because I don't know how to apply the conversion into linspace
theta2=linspace(theta,theta,10)
%eqns
for x=1:length(rho)
for z=1:length(theta)
u(x,z)=sin(2*theta(z)).*cos(2*theta(z));
end
end
%plot
polarplot(rho2,theta2,u) %error here too?

採用された回答

Star Strider
Star Strider 2021 年 3 月 12 日
I’m not certain where you’re going with your code or what you want to do with it.
Try something like this:
x=[-2 -1 0 1 2];
y=[-2 -1 0 1 2];
%cartesian --> polar
rho=sqrt(x.^2+y.^2);
theta=atan2(y,x);
%set up linspace with 10 pts
rho2=linspace(min(rho),max(rho),10); %this is where I'm confused because I don't know how to apply the conversion into linspace
theta2=linspace(min(theta),max(theta),10);
u = @(x,z) x.*sin(2*z).*cos(2*z);
[R,T] = ndgrid(rho2, theta2);
U = u(R,T);
[X,Y,Z] = pol2cart(T,R,U);
figure
surf(X, Y, Z)
grid on
view(60,60)
.
  2 件のコメント
Danny Allen
Danny Allen 2021 年 3 月 12 日
Thank you! This helped me a lot!
I'm just working through some random practices I found online and seeing what I can get as a result. It's more of a learning curve to get more practice on matlab.
Star Strider
Star Strider 2021 年 3 月 13 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by