How to Multiply a Value by a Matrix in MATLAB?

Click For Summary
SUMMARY

The discussion focuses on multiplying a value by a matrix in MATLAB, specifically using a rotation matrix defined as R. The correct approach involves defining a symbolic variable, theta, and constructing the matrix R with trigonometric functions: R = [cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1]. To perform the multiplication, users can assign a value to theta and utilize the subs() function to evaluate the matrix. An example operation provided is temp = R(-MarsAng)*[a_mars;0;0].

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of symbolic variables in MATLAB
  • Knowledge of trigonometric functions: cos() and sin()
  • Basic concepts of matrix multiplication
NEXT STEPS
  • Learn how to define and use symbolic variables in MATLAB
  • Explore the use of the subs() function for substituting values in symbolic expressions
  • Study matrix multiplication rules in MATLAB
  • Investigate the creation and manipulation of rotation matrices in MATLAB
USEFUL FOR

MATLAB users, engineers, and students working on projects involving matrix operations and symbolic computation.

Ewok
Messages
5
Reaction score
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
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)
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K