Help writing a function

1 view (last 30 days)
Jay
Jay on 5 Nov 2016
Answered: Walter Roberson on 5 Nov 2016
Can someone please help on how to write the following function please.
I have 3 3x3 Rotation Matrices.
2 of which are Identity Matrices.
R1 = eye(3,3)
R2 = eye(3,3)
% R3 Rotation Value Kappa Pre-Cal
R3(3,3) = zeros
R3(1,1) = cos(xHat_BM(3,1))
R3(1,2) = sin(xHat_BM(3,1))
R3(2,1) = -sin(xHat_BM(3,1))
R3(2,2) = cos(xHat_BM(3,1))
R3(3,3) = 1
xHat_BM will be updated for each iteration (separate section of code)
How do I create a function so that said function grabs the xHat_BM value from the script, uses it for the rotation angle calculations (R3 elements in the function), then outputs the updated R3 matrix (M_BM)back into the script for the next iteration?
Thanks in advance.

Accepted Answer

Walter Roberson
Walter Roberson on 5 Nov 2016
function R3 = update_R3(xHat_BM)
% R3 Rotation Value Kappa Pre-Cal
R3 = zeros(3,3);
R3(1,1) = cos(xHat_BM(3,1));
R3(1,2) = sin(xHat_BM(3,1));
R3(2,1) = -sin(xHat_BM(3,1));
R3(2,2) = cos(xHat_BM(3,1));
R3(3,3) = 1;
To use: have your script call
M_BM = update_R3(xHat_BM);

More Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!