How to define vector 'x' symbollically?

So, that its elements x(1), x(2), x(3) etc.. could be used later in script.

댓글 수: 1

Karan Gill
Karan Gill 2017년 2월 13일
Why do you need a symbolic vector "x"? Is the answer good enough or do you need what Walter describes?

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

답변 (1개)

Rik
Rik 2017년 2월 10일

0 개 추천

A = sym('a', [1 20])
A =
[ a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,...
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20]
If you need a dynamic length of the vector you can't use this, but I don't think that's even possible in Matlab.

댓글 수: 1

Walter Roberson
Walter Roberson 2017년 2월 10일
You are correct, you cannot have dynamic lengths of symbolic vectors in MATLAB. MATLAB does not really have subscripted symbolic variables: it has vectors that happen to contain symbols and you do normal numeric indexing.
For example, in what Rik shows, A(2) contains the individual symbol sym('a2'), rather than containing "A indexed at 2".
This is different than Mathematica or Maple, which do allow symbols to be subscripted, so for example in Maple you can have A[2] without A having been given any value; Maple knows it as an indexed symbol rather than symbol with a name that happens to be literally 'A' '[' '2' ']'

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

카테고리

태그

질문:

2017년 2월 10일

댓글:

2017년 2월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by