为syms创建多个变量

TYL*_*TYL 2 matlab

我想创建许多变量,如x1,x2,x3,以便在syms旁边使用,所以它看起来像这样:

syms x1 x2 x3 x4 ... x50 x51 .... xn

n是我需要的变量数.

有没有办法做到这一点?

Sar*_*ama 5

x = sym('x', [n 1]);
Run Code Online (Sandbox Code Playgroud)

这将创建n个符号变量,即x1, x2, x3 ......, xn您可以x(1), x(2), x(3)....., x(n)分别使用它们来访问它们

例如,当n = 4时,您将获得以下结果:

>> x

x =

 x1
 x2
 x3
 x4

>> x(1)

ans =

x1

>> x(3)

ans =

x3
Run Code Online (Sandbox Code Playgroud)