【问题标题】:How to plot figures with different angles in MATLAB如何在MATLAB中绘制不同角度的图形
【发布时间】:2016-05-15 19:52:09
【问题描述】:

我想绘制不同角度的曲线

v=10; 
teta=20; % angle of the projectile motion
vx=v*cos(teta); % velocity in x axis
vy=v*sin(teta); % velocity in y axis
x=0:20;
y=zeros(size(x));

y=vy.*(x./vx)-(0.5*9.81*(x./vx).^2); % here I calculate the height of the ball in y axis
plot(x,y)
set(gca,'ylim',[0,5])

如何每次更改 theta 以在同一图中绘制 20 度、40 度和 60 度的 theta?

谢谢

【问题讨论】:

    标签: matlab


    【解决方案1】:

    有几种方法可以满足您的需求。我在下面写下了其中一个:

    • 创建一个包含所有所需 theta 值的数组
    • 为每个 theta 生成 vx 和 vy。注意:您使用了 theta 的度数,但 sin 和 cos 函数以弧度为单位输入,因此您需要事先进行转换。
    • 在 for 循环中为每个 theta 值生成 y 值。
    • 绘制结果。

    代码如下:

    v=10; 
    teta=[20 40 60]; % angle of the projectile motion
    vx=v*cos(pi*teta/180); % velocity in x axis
    vy=v*sin(pi*teta/180); % velocity in y axis
    x=0:20;
    y=zeros(size(x));
    for i=1:length(vx)
        y(i,:)=vy(i).*(x./vx(i))-(0.5*9.81*(x./vx(i)).^2); % here I calculate the height of the ball in y axis
    end
    plot(x,y)
    set(gca,'ylim',[0,5])
    

    这会生成如下图所示: matlab plot for 3 theta values

    这是一个非常基本的解决方案。

    希望有帮助!

    【讨论】:

    • 谢谢你为什么在vx=v*cos(pi*teta/180); 中将theta除以180你的意思是这个值必须是弧度而不是等级
    • 是的。这只是将角度从度数转换为弧度的简单方法。因此,您可以输入以度为单位的角度,这将转换为余弦和正弦的弧度。
    • 另外,您可以使用 cosd,它是度数的余弦。 cosd - mathworks.com/help/matlab/ref/cosd.html, cos - mathworks.com/help/matlab/ref/cos.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多