带符号的 MATLAB 绘图错误
MATLAB Plotting Error with symbols
我正在使用下面的代码,并试图在微分位置函数后绘制速度和加速度曲线,但出现错误。有人可以帮帮我吗?
clc,clear,close all
t=0:.0001:2*pi/150;
theta= (150*t) ;
r=.2.*cos(theta)+sqrt(.75^2 - (.2.*sin(theta)).^2);
plot(t,r)
hold on
syms t
theta= (150*t);
r=.2.*cos(theta)+sqrt(.75^2 - (.2.*sin(theta)).^2);
v=diff(r,t);
a=diff(r,t,2);
t=0:.0001:2*pi/150;
plot(t,v);
plot(t,a);
hold off
您出现错误的原因是,当您使用 diff
时,您是在 象征性地使用它 。当你绘制东西时,你需要获得数字输出。因此,如果您想让它正常工作,您将需要额外调用 subs
,并使用 double
进行强制转换。所以:
syms t;
theta= (150*t);
r=.2.*cos(theta)+sqrt(.75^2 - (.2.*sin(theta)).^2);
v=diff(r,t);
a=diff(r,t,2);
%// Change
t_vec=0:.0001:2*pi/150;
v = double(subs(v, t, t_vec));
a = double(subs(a, t, t_vec));
hold on;
%// Change
plot(t_vec,v);
plot(t_vec,a);
hold off
我正在使用下面的代码,并试图在微分位置函数后绘制速度和加速度曲线,但出现错误。有人可以帮帮我吗?
clc,clear,close all
t=0:.0001:2*pi/150;
theta= (150*t) ;
r=.2.*cos(theta)+sqrt(.75^2 - (.2.*sin(theta)).^2);
plot(t,r)
hold on
syms t
theta= (150*t);
r=.2.*cos(theta)+sqrt(.75^2 - (.2.*sin(theta)).^2);
v=diff(r,t);
a=diff(r,t,2);
t=0:.0001:2*pi/150;
plot(t,v);
plot(t,a);
hold off
您出现错误的原因是,当您使用 diff
时,您是在 象征性地使用它 。当你绘制东西时,你需要获得数字输出。因此,如果您想让它正常工作,您将需要额外调用 subs
,并使用 double
进行强制转换。所以:
syms t;
theta= (150*t);
r=.2.*cos(theta)+sqrt(.75^2 - (.2.*sin(theta)).^2);
v=diff(r,t);
a=diff(r,t,2);
%// Change
t_vec=0:.0001:2*pi/150;
v = double(subs(v, t, t_vec));
a = double(subs(a, t, t_vec));
hold on;
%// Change
plot(t_vec,v);
plot(t_vec,a);
hold off