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

Scilab控制系统绘图GUI函数参数传递及变量类型匹配问题

问题根因

  • 变量属性调用错误:param.parameter、param.dom本身为字符串类型,代码中多余添加.string获取属性,SciNotes运行时作用域隔离更严格,控制台因可能存在遗留同名变量,才没有触发报错。
  • 分母参数类型不匹配:param.den存储的是字符串格式的表达式,syslin函数要求分子、分母输入为数值或多项式类型,直接传入字符串会触发类型错误。
  • 代码笔误:创建相位、奈奎斯特坐标轴时,多处错误复用gain_axes对象设置字体属性,会导致属性赋值异常。

修复方案

1. 修改displayProblem函数代码

// display function
function displayProblem(param)
    parameter = param.parameter;
    dom = param.dom;
    num = param.num;
    den = param.den;
    fmin = param.fmin;
    fmax = param.fmax;

    // 定义多项式变量
    s = poly(0, parameter);
    // 将字符串格式的分母表达式转为多项式
    den_poly = evstr(den);
    // 生成系统传递函数,直接传dom字符串即可
    h = syslin(dom, num, den_poly);

    // 清空当前坐标轴
    delete(gca());

    // 绘制增益曲线
    gain_axes = newaxes();
    gain_axes.title.font_size = 3;
    gainplot(h, fmin, fmax);
    gain_axes.axes_bounds = [1/3, 0, 1/3, 1/2];
    gain_axes.title.text = "Gain Plot"; 

    // 绘制相频曲线
    phase_axes = newaxes();
    phase_axes.title.font_size = 3;
    phaseplot(h, fmin, fmax);
    phase_axes.axes_bounds = [1/3, 1/2, 1/3, 1/2];
    phase_axes.title.text = "Phase Plot";

    // 绘制奈奎斯特曲线
    nyquist_axes = newaxes();
    nyquist_axes.title.font_size = 3;
    nyquist(h);
    nyquist_axes.axes_bounds = [2/3, 0, 1/3, 1/2];
    nyquist_axes.title.text = "Nyquist Plot";

endfunction

2. 调用验证

原有param结构体定义不需要修改,直接调用函数即可正常运行:

param = [];
param.parameter = "s";
param.dom = "c";       //domain(c for continuous, d for discrete)
param.num = 1;          //numerator  of transfer function
param.den = "(s+1)^3";  //denominator 
param.fmin = 0.01;     //min freq of the plot
param.fmax = 100;      //max freq

displayProblem(param)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.24 19:54:02