Message Boards Message Boards

0
|
4491 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to input a rotated vector?

Posted 9 years ago

New to Mathematica, 10.1, following the guide, but getting wrong results. I'm trying to input a vector after being transformed by a rotation matrix, as:

m1={{a Cos Theta + b Sin Theta},{-a Sin Theta + b Cos Theta}}

but I get a row of 4 numbers as output? I'm trying to get a visualization of this vector so I can compare it with, for example:

m1={{a Cos Theta - b Sin Theta},{a Sin Theta + b Cos Theta}}

and a few other variations. So please give me the exact input I should be typing? Much appreciated, Alan

POSTED BY: Alan Smith
5 Replies
Posted 9 years ago

Hi Alan,

Mathematica has a "front end" and a "kernel." The front end is the user interface; The kernel performs the computations. The values of variables, the real state of the system, is in the kernel. Notebooks are creatures of the front end. There can be several open. You can close them and open new ones. But there is only one kernel, and all notebooks use it for computation. If you have several notebooks open, and one notebook defines x=3, that is in the kernel. Any other notebook wanting to use x will find it is equal to 3. If you close the notebooks, but not the kernel -- that is you do not quit Mathematica -- a newly opened notebook will still find all the old definitions in existence.

To start fresh you can quit Mathematica entirely and restart it. Or you can go to the menu bar and select Evaluation->Quit Kernel. You can also Clear all variables in the Global context with Clear["Global`*] as I do below.

I highly recommend sometime with The Virtual Book

Also the help system in Mathematica is excellent. For some specific answers see the code below:

In[1]:= Clear["Global`*"]

In[2]:= (* a general matrix is just a regular list of lists *)
m = {{a, b}, {c, d}};

In[3]:= (* The dot operator is used for multiplication of vectors, \
matrices, and tensors.*)
m.{x, y}

Out[3]= {a x + b y, c x + d y}

In[4]:= (*  You just create them at need.  *)
{{1, 2}, {3, 4}}.{5, 6}

Out[4]= {17, 39}

In[5]:= {1, 2}.{3, 4}

Out[5]= 11
POSTED BY: David Keith
Posted 9 years ago

Thanks David, but in 1) I wanted to know how to look at similar matrices to the rotation matrix as well? I tried Clear[y], got the same result. I note that even when I start a new notebook, it seems to keep previous values - is there a clear all that will guarantee nothing left over from previous work? Cheers ALan

POSTED BY: Alan Smith
Posted 9 years ago

Hi Alan,

On 1: What you have written is correct. Which is the same syntax you see in Out[1]: above. All RotationMatrix has done is generate a matrix, which in Mathematica is just a list of lists. You've done the same thing.

On 2: It appears to me that you have previously assigned to y the value Sqrt[1-x^2]. Try executing Clear[y] and evaluate it again.

Best, David

POSTED BY: David Keith
Posted 9 years ago

Thanks David.

1) r = RotationMatrix[theta] worked fine. If I wanted to try different matrices, for example {{Cos[theta], Sin[theta]}, {-Sin[theta], Cos[theta]}} how would I do that?

2) When I input r.{x, y} I got out[55]= {x Cos[theta] - Sqrt[1 - x^2] Sin[theta], Sqrt[1 - x^2] Cos[theta] + x Sin[theta]}

Not sure whats different?

Thanks Alan

POSTED BY: Alan Smith
Posted 9 years ago
In[1]:= r = RotationMatrix[theta]

Out[1]= {{Cos[theta], -Sin[theta]}, {Sin[theta], Cos[theta]}}

In[2]:= r.{x, y}

Out[2]= {x Cos[theta] - y Sin[theta], y Cos[theta] + x Sin[theta]}
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract