【问题标题】:Array Indices Syms Error when running code运行代码时数组索引 Syms 错误
【发布时间】:2021-04-16 23:39:11
【问题描述】:
clear;
clc;

m=18;
L=4;
g=9.81;

syms ax alpha ay na nb
S = solve(ax - .5.*L.*alpha.*cos(30)==0, 0 ==(ax + alpha.*L.*.5.*cos(30)).*sin(20) + (ay + alpha.*.5.*L.*sin(30)).*cos(30), na + nb.*sin(20) == m.*ax, nb.*cos(20) - m.*g == m.*ay, -na(L./2.*cos(30)) + nb.*cos(20).*(L./2.*sin(30)) + nb.*sin(20).*(L./2.*cos(30)) == .5.*m.*L.^2.*alpha);

S = [S.ax, S.alpha, S.ay, S.na, S.nb]

不断获取数组索引必须是正整数或逻辑值错误

【问题讨论】:

    标签: matlab


    【解决方案1】:

    看起来脚本需要在-na 行中的solve() 行中添加一个乘号。试试下面这个 sn-p:

    clear;
    clc;
    
    m=18;
    L=4;
    g=9.81;
    
    syms ax alpha ay na nb
    S = solve(ax - .5.*L.*alpha.*cos(30)==0, 0==(ax + alpha.*L.*.5.*cos(30)).*sin(20) + (ay + alpha.*.5.*L.*sin(30)).*cos(30), na + nb.*sin(20) == m.*ax, nb.*cos(20) - m.*g == m.*ay, -na.*(L./2.*cos(30)) + nb.*cos(20).*(L./2.*sin(30)) + nb.*sin(20).*(L./2.*cos(30)) == .5.*m.*L.^2.*alpha);
    S = [S.ax, S.alpha, S.ay, S.na, S.nb];
    disp(S);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多