4
$\begingroup$

It is my understanding that undefined symbols are considered scalars, so I can't index variables that aren't defined. enter image description here

It is possible to define a symbol as a vector of symbols as follows, allowing each symbol to be individually addressable:

y1
y2
y = {y1, y2}
y[[1]]

enter image description here

Is it possible to create an n-dimensional vector of real numbers?

One possible use case is taking the Jacobian of a function at a point.

x = {x1, x2}; (* Tedious to do by hand if n is large *)
x // MatrixForm

f = {-x[[1]] + x[[1]]*x[[2]],   -x[[2]]};
f // MatrixForm

A = D[f, {x}] /. {x1->0, x2->0}; (* The Jacobian of F at (0, 0) *)
A // MatrixForm

enter image description here

$\endgroup$
3

2 Answers 2

4
$\begingroup$
xs = Array[Indexed[x, #] &, 2]  (* {Subscript[x, 1],Subscript[x, 2]} *)
xs[[1]]  (* Subscript[x, 1] *)
f = {-xs[[1]] + xs[[1]]*xs[[2]], -xs[[2]]};
f // MatrixForm  (* nice symoblic matrix *)

A = D[f, {xs}] /. {xs[[1]] -> 0, xs[[2]] -> 0}; (* Jacobian of F at (0,0)*)
A // MatrixForm  (* what you have above *)
$\endgroup$
3
$\begingroup$

Try this:

SymbolicVector[symbol_Symbol, row_Integer?Positive] := ToExpression[
Array[ToString[symbol] <> ToString[FromDigits[{##}]] &, row]]

Test:

SymbolicVector[y, 3]
(*{y1, y2, y3}*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.