[英]Plotting complex function in MATLAB (polar)?
I have tried to plot this function: 我试图绘制这个函数:
t=linspace(0,2*pi,100);
a=input('a= ');
b=input('b= ');
c=input('c= ');
k = a*(1-(sin(3*t)).^(2*b))+c;
polar(t,k)
% a=2.6
% b=0.4
% c=5
Each time, I get the following message: 每次,我收到以下消息:
Warning: Imaginary parts of complex X and/or Y arguments ignored.
警告:忽略复杂X和/或Y参数的虚部。
I have tried the pol2cart method as such: 我已经尝试了pol2cart方法:
t=linspace(0,2*pi,100);
a=input('a= ');
b=input('b= ');
c=input('c= ');
k = a*(1-(sin(3*t)).^(2*b))+c;
[x,y] = pol2cart(t,k);
plot(x,y)
I got the same message again. 我又收到了同样的消息。 I have tried to convert it to spherical coordinates, it didn't work.
我试图将其转换为球坐标,但它不起作用。 I have also tried the arrayfun method as suggested in a forum answer, it didn't work as well.
我也尝试过在论坛答案中建议的arrayfun方法,它也没有用。 Can someone please help me?
有人可以帮帮我吗? Thank you!
谢谢!
Your problem is in your function. 你的问题在于你的功能。
k
contains imaginary numbers, because of this: k
包含虚数,因为:
sin(3*t).^(0.8)
If you want to make sure it doesn't contain imaginary numbers, you need to increase b
. 如果要确保它不包含虚数,则需要增加
b
。 Bottom line is, fix your formula. 底线是,修复你的公式。 I can only suppose you mean something like this, but there could be other solutions.
我只能假设你的意思是这样,但可能有其他解决方案。 Essentially, I think you mean to take the exponent of 1-sin, not sin.
从本质上讲,我认为你的意思是采取1罪的指数,而不是罪。
k=a*((1-sin(3*t)).^(2*b))+c;
This gives the following plot (From Octave, but it should be the same) 这给出了下面的图(从Octave,但它应该是相同的)
I figured this out by `plot(k). 我用'plot(k)来计算出来。 If k contains imaginary, it will plot the real vs imaginary components.
如果k包含虚数,它将绘制实部与虚部。 If it is purely real, it will plot the line vs time.
如果它纯粹是真实的,它将绘制线与时间的关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.