How to Multiply a Value by a Matrix in MATLAB?

R = [0 1 0; -1 0 0; 0 0 1]In summary, to create a matrix and multiply it by a value in MATLAB, you can define a symbolic variable for the functions, write the matrix, assign a value to the variable, and use subs() to calculate the value of the matrix.
  • #1
Ewok
5
0
Hi, this isn't a homework question as such, but I'd appreciate some advice as it is a part of a project that I'm doing.

I'm trying to write some MATLAB code and need to create a matrix and multiply some value by this matrix

ie.
R(*)=[cos(*) sin(*) 0; -sin(*) cos(*) 0; 0 0 1]

but I'm not sure how to write/use it. Basically I have a formula whereby a value is multiplied by this matrix (or visa versa), however I'm not sure how to relate the two in code.
The stars in the above matrix represent the value to be multiplied, so do I need to simply write the matrix as:

R=[cos sin 0; -sin cos 0; 0 0 1]

or

R()=[cos() sin() 0; -sin() cos() 0; 0 0 1]

or indeed something else for this operation to work??

p.s An example of the operation that I'm trying to do is:

temp = R(-MarsAng)*[a_mars;0;0];

Thanks
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
First define a symbolic variable for the functions, say theta. Then write the matrix R. Later, you can assign a value to theta, and use subs(R) to calculate the value of R.
Code:
syms theta;
R = [cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1];
x = pi/2;
subs(R)
 

What is Matlab and why is it commonly used for matrix expressions?

Matlab is a high-level programming language and environment that is commonly used in scientific computing. It is particularly well-suited for matrix expressions because it has built-in functions and syntax specifically designed for manipulating and analyzing matrices.

How do I create a matrix in Matlab?

To create a matrix in Matlab, you can use the built-in function "zeros" or "ones" to create matrices filled with zeros or ones, respectively. You can also use the square brackets notation to manually enter the values of the matrix elements.

What are some common operations for matrix expressions in Matlab?

Some common operations for matrix expressions in Matlab include addition, subtraction, multiplication, and division. Other useful operations include transposing, finding the determinant, and finding the inverse of a matrix.

Can I perform element-wise operations on matrices in Matlab?

Yes, Matlab allows for element-wise operations on matrices using the dot notation. For example, you can use the dot operator (.) to perform element-wise multiplication of two matrices.

What are some useful functions for working with matrices in Matlab?

Matlab has many built-in functions for working with matrices, including those for finding the mean, median, and standard deviation of a matrix. There are also functions for finding the eigenvalues and eigenvectors of a matrix, as well as for reshaping and concatenating matrices.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
560
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
944
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Quantum Physics
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
992
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
904
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
Back
Top