运行代码时出现数组索引符号错误

时间:2021-04-16 23:39:11

标签: matlab

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]

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

1 个答案:

答案 0 :(得分:0)

看起来脚本在 -na 行中需要一个乘号继续 solve()。试试下面的这个片段:

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);