How to create a Symbolic vector

조회 수: 43 (최근 30일)
Amin Mohammadi
Amin Mohammadi 2021년 2월 27일
댓글: Star Strider 2021년 2월 27일
Hi, I want to define n symbolic variables How to define: Syms x1 x2 ... xn ?! n is input function.

답변 (1개)

Star Strider
Star Strider 2021년 2월 27일
Try this::
n = inputdlg('Enter the length of the vector (integer): ');
n = str2double(n);
syms x
x = sym('x',[1 n])
producing (for n = 5):
x =
[x1, x2, x3, x4, x5]
Reference as you would any other vector:
v3 = x(3)
producing:
v3 =
x3
.
  댓글 수: 2
Amin Mohammadi
Amin Mohammadi 2021년 2월 27일
Thanks. But I want to define variables x1 to xn as sym. Actually elements of the vector are symbolic! Syms x1 x2...xn
Star Strider
Star Strider 2021년 2월 27일
My pleasure!
That is exactly what my code example does. The elements of the ‘x’ vector here are symbolic. See the documentation on the sym function for details.
Running:
whos x
after running my code reveals:
Name Size Bytes Class Attributes
x 1x5 8 sym
So it creates a symbolic vector for ‘x’.
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by