You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MatLab绘制螺旋曲线遇阻:函数报错与空图问题求助

解决Matlab绘制螺旋曲线的问题

你的核心问题在于:

  • spiralplus 是一个恒成立的等式(化简后左右两边完全相等),所以 fimplicit3 找不到任何满足该等式的非平凡点,因此输出空白图形。
  • fplot/plot 报错是因为你传入的是等式而非函数句柄或可直接计算的数值序列。

正确的绘图方法

既然 x3(t) 和 x4(t) 都是参数 t 的函数,直接绘制参数曲线即可(x3为横轴,x4为纵轴,t为参数):

方法1:符号函数转函数句柄用fplot

syms t ;

rf = 4;
m=2;
b=1;
M=m+b;
d=0.1;
k=1;
g = M*d/(2*(m*b));%gamma
w = sqrt(k*M/(m*b));%omega
delta=sqrt(abs(g^2-w^2));

x3plus=-(1/w^2*b)*exp(-g*t)*cos(delta*t)-(g/w^2*b)*exp(-g*t)*sin(delta*t)+(1/w^2*b);
x4plus=diff(x3plus,t);

% 用fplot绘制参数曲线,指定t的范围(比如0到20)
fplot(x3plus, x4plus, [0, 20])
xlabel('x3(t)')
ylabel('x4(t)')
title('Spiral Curve')
grid on

方法2:数值计算用plot

如果更倾向于数值计算(避免符号运算的开销),可以生成t的数值数组,计算对应的x3和x4值:

rf = 4;
m=2;
b=1;
M=m+b;
d=0.1;
k=1;
g = M*d/(2*(m*b));%gamma
w = sqrt(k*M/(m*b));%omega
delta=sqrt(abs(g^2-w^2));

% 定义t的范围和步长
t = 0:0.01:20;
% 计算x3和x4的数值
x3 = -(1/w^2*b).*exp(-g*t).*cos(delta*t)-(g/w^2*b).*exp(-g*t).*sin(delta*t)+(1/w^2*b);
x4 = g*(1/w^2*b).*exp(-g*t).*cos(delta*t) + (delta/w^2*b).*exp(-g*t).*sin(delta*t); % 直接写出x4的表达式

plot(x3, x4)
xlabel('x3(t)')
ylabel('x4(t)')
title('Spiral Curve')
grid on

为什么原代码的spiralplus没用?

对spiralplus执行化简操作:

simplify(spiralplus)

会得到0 == 0的结果,这是一个恒等式,没有任何实际约束条件,所以fimplicit3无法绘制出有效图形。

内容的提问来源于stack exchange,提问作者dodo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 02:55:10