Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4 Write a computer program that takes as input 2 rotation angles and (in degrees

ID: 3883690 • Letter: 4

Question

4 Write a computer program that takes as input 2 rotation angles and (in degrees) and calculates the DCMs C3 (a) and Cl (d) corresponding to a rotation about the 3-axis and a rotation about the 1- axis, respectively. Then calculate the product D-CiC. The program should output the following - ALL labeled with their names, and units f any) (a) the input angles (b) Ci, Cs and D Example () output from Matlab alpha = 125.0 deg beta = 75 deg C-1 = 1.0000 0.0000 0.0000 0 0000 0.2588 0.9569 0.0000-0.9659 0.2588 Run the code for the case = 125 deg, and = 75 deg. Hand in a printed copyo of the out- .Remember, most compilers/interpreters (including Matlab) use radians for angles Be sure to save your code files since you can use them in later assignments/projects. You wil find it useful to write separate functions, methods, or subrouties to calculate Ci and C3. Pass the value of the angle as an input and return the DCM as the result. A similar approach for multiplyig two DCMs is also useful if you are coding in a language that does not include matrix multiplication as a standard operation. For this assignment, it's ok to output everything to the screen, but you will find it useful to ear how to write output to a file . See the programming help link i Canvas for examples of how to write output to a file, how to include character strings for labels, etc. there are examples for Matlab and C++ . Upload your code in Canvas in the section for this assignment. For multiple files, please put them together in a zip file and ur'...' 2 of 2

Explanation / Answer

Hi,

Find the Answer below, hope function will be useful for you -

function dcm()

alphaDeg = 125.0;
betaDeg = 75.0;
% Calculation of C1
C1 = dcmfromeuler(deg2rad(betaDeg),0,0,'zyx');
% Calculation of C3
C3 = dcmfromeuler(0,0,deg2rad(alphaDeg),'zyx');
% Calculation of D = C1*C3
D = C1*C3;

% Display
disp('C_1 :');
disp(C1);
disp('C_3 :');
disp(C3);
disp('D :');
disp(D);

% % Computes Direction Cosine Matrix from Euler angles (in radians) for
% % six basic sequence of rotations around X(Roll),Y(Pitch) and Z(Yaw) axis.
% % Allowed rotations sequences:
% % xyz, xzy, yxz, yzx, zxy, zyx OR rpy, ryp, pry, pyr, yrp, ypr

function DCM=dcmfromeuler(roll,pitch,yaw,order)

rM=[1    0           0;
    0    cos(roll)   sin(roll);
    0    -sin(roll) cos(roll)];

pM=[cos(pitch)      0       -sin(pitch);
    0               1       0;
    sin(pitch)      0       cos(pitch)];

yM=[cos(yaw)        sin(yaw)        0;
    -sin(yaw)       cos(yaw)        0;
    0               0               1];

% % -------------------------------------------------------------------------
% % for Rotations if order of rotations is 'rpy' (i.e. roll-->pith-->yaw)
% % then in matrix multiplication we would multiply them in reverse order
% % i.e. first muliply yM with pM let
% % T=yM*pM then multiply T with rM i.e
% % Ans=T*rM
% % or Ans=(yM*yM)*rM
% % where rM,yM and yM are rotation matrices
% % -------------------------------------------------------------------------
if(strcmpi(order,'xyz')==1 || strcmpi(order,'rpy')==1)
    DCM=(yM*pM)*rM;
elseif(strcmpi(order,'xzy')==1 || strcmpi(order,'ryp')==1)
    DCM=(pM*yM)*rM;
elseif(strcmpi(order,'yxz')==1 || strcmpi(order,'pry')==1)
    DCM=(yM*rM)*pM;
elseif(strcmpi(order,'yzx')==1 || strcmpi(order,'pyr')==1)
    DCM=(rM*yM)*pM;
elseif(strcmpi(order,'zxy')==1 || strcmpi(order,'yrp')==1)
    DCM=(pM*rM)*yM;
elseif(strcmpi(order,'zyx')==1 || strcmpi(order,'ypr')==1)
    DCM=(rM*pM)*yM;
else
    error('could not recognized the sequence of rotation')
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote