# Help writing a function

2 vues (au cours des 30 derniers jours)
Jay le 5 Nov 2016
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?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Walter Roberson le 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);
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Chemistry dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by