TYL
TYL

Reputation: 1637

Creating multiples variables for syms

I want to create many variables such as x1, x2, x3 to use beside syms so it will look something like this:

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

n is the number of variables I need.

Is there any way to do that?

Upvotes: 2

Views: 299

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

x = sym('x', [n 1]);

This will create n symbolic variables i.e. x1, x2, x3 ......, xn and you can access them using x(1), x(2), x(3)....., x(n) respectively

For example with n=4, you'll get these results:

>> x

x =

 x1
 x2
 x3
 x4

>> x(1)

ans =

x1

>> x(3)

ans =

x3

Upvotes: 5

Related Questions