how to create matrices efficiently

Hi!
let's say I have 10 different angles. So I have a1, a2, a3, ... a10. I need to calculate 10 different 2x2 matrices depending those angles and save them. So my matrices will be [cos(a1), sin(a1); sin(a1), -cos(a1)] and so on. Question is how I can make those matrices without writing all 10 matrix by hand? I've tried make those by for loop and I think my problem is that I need multiple matrices instead vectors.

2 个评论

Just a note of caution. In case those 2x2 matrices were intended to be rotation matrices by the angles a1, a2, ..., the signs are wrong in the second column.

请先登录,再进行评论。

 采纳的回答

Here is a start
>> f = @(a) [cos(a), sin(a); sin(a), -cos(a)];
>> f(pi)
ans =
-1.0000 0.0000
0.0000 1.0000
>>
where
f = @(a) [cos(a), sin(a); sin(a), -cos(a)];
Search the help for "Anonymous Functions"

更多回答(1 个)

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by