Matlab求解方程中多个变量的顺序
Order of multiple variables in Matlab solve equations
我读了 Matlab documentation 但仍然难以理解 Matlab 求解方程中多个变量的顺序
例如
syms f1(R,L) f2(R,L);
f1 = (80+R)^2 + (120*pi*L)^2 - 232^2;
f2 = R^2 + (120*pi*L)^2 - 176^2;
[R,L] = solve (f1,f2);
fprintf('Resistor is %s Ω\n',round(R,3));
fprintf('Inductance is %s H\n',round(L,3));
如果我用 Z
替换变量 L
,结果将是相反的顺序。
好像是字母顺序,不知道具体规则是什么
根据您链接的 solve
的文档:
Y = solve(eqns,vars)
solves the system of equations eqns
for the variables vars
and returns a structure that contains the solutions. If you do not specify vars
, solve
uses symvar
to find the variables to solve for.
您没有指定要求解哪些变量,因此 MATLAB 会尝试通过调用 symvar
来推断这一点。 symvar
返回的标识符的顺序似乎没有明确记录,因此我不建议依赖任何特定的顺序。
如果您想指定 solve
应该求解哪些变量,以及它们在输出中的顺序,请将它们作为 solve
的第二个参数传递到数组中:
[R, L] = solve([f1, f2], [R, L]);
我读了 Matlab documentation 但仍然难以理解 Matlab 求解方程中多个变量的顺序
例如
syms f1(R,L) f2(R,L);
f1 = (80+R)^2 + (120*pi*L)^2 - 232^2;
f2 = R^2 + (120*pi*L)^2 - 176^2;
[R,L] = solve (f1,f2);
fprintf('Resistor is %s Ω\n',round(R,3));
fprintf('Inductance is %s H\n',round(L,3));
如果我用 Z
替换变量 L
,结果将是相反的顺序。
好像是字母顺序,不知道具体规则是什么
根据您链接的 solve
的文档:
Y = solve(eqns,vars)
solves the system of equationseqns
for the variablesvars
and returns a structure that contains the solutions. If you do not specifyvars
,solve
usessymvar
to find the variables to solve for.
您没有指定要求解哪些变量,因此 MATLAB 会尝试通过调用 symvar
来推断这一点。 symvar
返回的标识符的顺序似乎没有明确记录,因此我不建议依赖任何特定的顺序。
如果您想指定 solve
应该求解哪些变量,以及它们在输出中的顺序,请将它们作为 solve
的第二个参数传递到数组中:
[R, L] = solve([f1, f2], [R, L]);