Creating an arbitary symbolic matrix in Matlab

In summary, the speaker is new to using MATLAB and is trying to write a function that creates a matrix with symbolic variable names. They are unsure of the syntax for creating these names and are seeking suggestions. They mention using nested loops but are still struggling to achieve the desired result.
  • #1
EbolaPox
101
1

Homework Statement


Hi everyone, I'm new to using MATLAB and had a quick question. I'm trying to write a function such that my input into it is a number, say n, and it produces an n by n matrix with symbolic variables with names of the form aij , where i and j are numbers that refer to its row and column positions. This didn't seem like it would be too terribly tough, but I'm not sure how to make give my matrix these variable names of the form aij. I figured I could write a loop of some form that went from 0 to n and gave each an a1n or something of that form name, just to get at least one row, but I'm not too sure what syntax to use to give the symbolic variable its name. I was hoping I could write a loop with a variable i that ranged from 0 to n, and then do something like syms a'i' or something like that. I thought maybe if I turned the number i into a string, I could do something like that to make a bunch of symbolic variables, but I still had no luck. Any suggestions would be very appreciated. Thanks!
 
Physics news on Phys.org
  • #2
I'm not familiar with Matlab. But wouldn't this involve two nested loops, no matter what programming language is used?
 
  • #3


I would suggest using the "sym" function in MATLAB to create a symbolic matrix with arbitrary variables. This function allows you to specify the size of the matrix and the variable names. For example, you can use the following code:

A = sym('a',[n,n]);

This will create an n by n matrix with symbolic variables named aij, where i and j are the row and column indices. You can then use a loop to assign values to these variables if needed. I hope this helps with your task.
 

1. What is an arbitrary symbolic matrix?

An arbitrary symbolic matrix is a matrix with elements that are symbolic variables, rather than numerical values. This allows for more flexibility in mathematical operations and allows for symbolic manipulations.

2. How do I create an arbitrary symbolic matrix in Matlab?

To create an arbitrary symbolic matrix in Matlab, you can use the "sym" function. For example, if you want to create a 3x3 matrix with symbolic variables a, b, and c as elements, you can use the command "A = sym('a',[3,3])". This will create a 3x3 matrix filled with the symbolic variable a.

3. Can I perform operations on arbitrary symbolic matrices in Matlab?

Yes, Matlab has built-in functions for performing operations on symbolic matrices. These include addition, subtraction, multiplication, and division. You can also use other symbolic functions such as "subs" to substitute values for the symbolic variables in the matrix.

4. How can I convert an arbitrary symbolic matrix to a numerical matrix in Matlab?

To convert an arbitrary symbolic matrix to a numerical matrix, you can use the "double" function. This will convert all the elements in the matrix to their numerical values. For example, "B = double(A)" will convert the symbolic matrix A to a numerical matrix B.

5. Are there any limitations to using arbitrary symbolic matrices in Matlab?

While arbitrary symbolic matrices offer more flexibility, they can also be more computationally intensive compared to numerical matrices. Additionally, symbolic computations may not always be as accurate as numerical computations. It is important to be aware of these limitations when using arbitrary symbolic matrices in Matlab.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
930
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Linear and Abstract Algebra
Replies
6
Views
837
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Differential Equations
Replies
3
Views
2K
  • Linear and Abstract Algebra
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
3K
Back
Top