Matlab: Converting a vector to syms?

In summary, to convert a vector to symbolic variables in Matlab, you can use the sym function. If the vector contains both numerical and symbolic values, the resulting symbolic variable will only contain the symbolic values. To convert a vector to a matrix of symbolic variables, use the sym function along with the reshape function. To convert a symbolic vector back to a numerical vector, use the double function. You can also convert a vector with complex values to symbolic variables, but to convert it to a matrix of symbolic variables, you will need to use the complex function along with sym and reshape.
  • #1
skybox
37
0
Matlab: Converting a vector to syms??

Hi Guys,

I have a vector in the following form:
Z = [2 3]

I want it to be displayed as (Z-2)*(Z+3). Is there any function in Matlab to do this? I searched help files and don't see any way of achieving this other than a loop.

Thanks in advance for the help!
 
Physics news on Phys.org
  • #2


I think you have to create your own function for this one. Shouldn't be difficult.
The polynomial (Z-2)*(Z+3) is not equivalent to the vector [2 3] but to [1 1 -6].

But who knows. I'm not familier with symbolic computation.
 
  • #3


I can suggest using the "poly2sym" function in Matlab to convert a vector into symbolic variables. This function takes in the vector as an input and returns a symbolic polynomial expression. In this case, you can use the following code:

Z = [2 3];
syms x
poly2sym(Z, x)

This will give you the desired output of (x-2)*(x+3). Additionally, you can also use the "sym" function to convert a vector into a symbolic variable and then manipulate it as needed. I hope this helps!
 

1. How do I convert a vector to symbolic variables in Matlab?

To convert a vector to symbolic variables in Matlab, you can use the sym function. For example, if your vector is called vec, you can use sym('vec') to create a symbolic variable called vec.

2. Can I convert a vector with both numerical and symbolic values to syms in Matlab?

Yes, you can convert a vector with both numerical and symbolic values to syms in Matlab. However, the resulting symbolic variable will only contain the symbolic values, and the numerical values will be lost.

3. How can I convert a vector to a matrix of symbolic variables in Matlab?

To convert a vector to a matrix of symbolic variables in Matlab, you can use the sym function along with the reshape function. For example, if your vector is called vec and you want to convert it to a 3x3 matrix, you can use reshape(sym('vec'),3,3).

4. Is there a way to convert a symbolic vector back to a numerical vector in Matlab?

Yes, you can use the double function to convert a symbolic vector back to a numerical vector in Matlab. For example, if your symbolic vector is called sym_vec, you can use double(sym_vec) to get a numerical vector.

5. Can I convert a vector with complex values to symbolic variables in Matlab?

Yes, you can convert a vector with complex values to symbolic variables in Matlab. The resulting symbolic variable will also be complex. However, if you want to convert a complex vector to a matrix of symbolic variables, you will need to use the complex function along with sym and reshape.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
566
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Back
Top