MATLAB Matlab - matrix expressions

  • Thread starter Ewok
  • Start date
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

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]


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];

Last edited by a moderator:

Wrichik Basu

Gold Member
2018 Award
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.
syms theta;
R = [cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1];
x = pi/2;

Want to reply to this thread?

"Matlab - matrix expressions" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving