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

GNUPLOT生成拉格朗日双摆GIF报错:No Previous filename

Gnuplot生成拉格朗日双摆GIF时出现“No Previous filename”错误

我已经花了5小时尝试制作拉格朗日双摆的GIF动画,数学推导部分确认没问题,但每次运行代码都会弹出“No Previous filename”错误,根本生成不了GIF,网上搜了一圈也没找到解决方案。

我用的是GNUPLOT 5.4 Patch 8,通过四阶龙格-库塔法求解二维模型的微分方程,代码如下:

# Constants
m1 = 1.0
m2 = 1.0
L1 = 1.0
L2 = 1.0
g = 9.8

# Initial conditions
theta1_0 = 0.0
theta2_0 = 0.0
theta1_dot_0 = 0.0
theta2_dot_0 = 0.0

# Time
dt = 0.01
t_max = 10.0

# Initial values of theta1, theta2, theta1_dot, and theta2_dot
theta1 = theta1_0
theta2 = theta2_0
theta1_dot = theta1_dot_0
theta2_dot = theta2_dot_0

# Set output file
set term gif animate delay 10 optimize optimize
set output "double_pendulum.gif"

# Numerical integration using the 4th order Runge-Kutta method
do for [i = 1:int(t_max / dt)] {
    # Calculate derivatives
    dtheta1_dt = theta1_dot
    dtheta2_dt = theta2_dot
    dtheta1_dot_dt = (m2 * g * sin(theta2) * cos(theta1 - theta2) - m2 * sin(theta1 - theta2) * (L1 * theta1_dot**2 * cos(theta1 - theta2) + L2 * theta2_dot**2) - (m1 + m2) * g * sin(theta1)) / (L1 * (m1 + m2 * sin(theta1 - theta2)**2))
    dtheta2_dot_dt = (( (m1 + m2) * (L1 * theta1_dot**2 * sin(theta1 - theta2) - g * sin(theta2) + g * sin(theta1) * cos(theta1 - theta2)) + m2 * L2 * theta2_dot**2 * sin(theta1 - theta2) * cos(theta1 - theta2)) / (L2 * (m1 + m2 * sin(theta1 - theta2)**2)))

    # Update the values using the 4th order Runge-Kutta method
    k1_theta1 = dt * dtheta1_dt
    k1_theta2 = dt * dtheta2_dt
    k1_theta1_dot = dt * dtheta1_dot_dt
    k1_theta2_dot = dt * dtheta2_dot_dt

    k2_theta1 = dt * (dtheta1_dt + 0.5 * k1_theta1_dot)
    k2_theta2 = dt * (dtheta2_dt + 0.5 * k1_theta2_dot)
    k2_theta1_dot = dt * (dtheta1_dot_dt + 0.5 * dtheta1_dot_dt)
    k2_theta2_dot = dt * (dtheta2_dot_dt + 0.5 * dtheta2_dot_dt)

    k3_theta1 = dt * (dtheta1_dt + 0.5 * k2_theta1_dot)
    k3_theta2 = dt * (dtheta2_dt + 0.5 * k2_theta2_dot)
    k3_theta1_dot = dt * (dtheta1_dot_dt + 0.5 * dtheta1_dot_dt)
    k3_theta2_dot = dt * (dtheta2_dot_dt + 0.5 * dtheta2_dot_dt)

    k4_theta1 = dt * (dtheta1_dt + k3_theta1_dot)
    k4_theta2 = dt * (dtheta2_dt + k3_theta2_dot)
    k4_theta1_dot = dt * (dtheta1_dot_dt + dtheta1_dot_dt)
    k4_theta2_dot = dt * (dtheta2_dot_dt + dtheta2_dot_dt)

    theta1_dot = theta1_dot + (1.0 / 6.0) * (k1_theta1_dot + 2.0 * k2_theta1_dot + 2.0 * k3_theta1_dot + k4_theta1_dot)
    theta2_dot = theta2_dot + (1.0 / 6.0) * (k1_theta2_dot + 2.0 * k2_theta2_dot + 2.0 * k3_theta2_dot + k4_theta2_dot)
    theta1 = theta1 + (1.0 / 6.0) * (k1_theta1 + 2.0 * k2_theta1 + 2.0 * k3_theta1 + k4_theta1)
    theta2 = theta2 + (1.0 / 6.0) * (k1_theta2 + 2.0 * k2_theta2 + 2.0 * k3_theta2 + k4_theta2)

    # Update time
    t = i * dt

    # Plot the double pendulum motion
    if (i == 1) {
        set xrange [-2:2]
        set yrange [-2:2]
        plot L1 * sin(theta1), -L1 * cos(theta1), L1 * sin(theta1) + L2 * sin(theta2), -L1 * cos(theta1) - L2 * cos(theta2) with lines title 'Pendulum 1', '' using 3:4 with lines title 'Pendulum 2'
    } else {
        replot
    }
    pause 0.01
}

错误截图:
错误提示

恳请各位帮忙看看怎么解决这个问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 21:37:54