In: Civil Engineering
Write a function script DirCos.m that takes a vector (any row or column array) as the argument and returns the direction cosines for that vector. This is for a MatLab script
Consider a vector a.i + b.j + c.k, Where a,b,c are the direction magnitudes and i,j,k are unit functions.
This vector can be represented as <a b c>
Direction cosine of the vector are,
cos =
cos =
cos =
MATLAB CODE
for i=1:3
a(i) = input("Enter the value of vector : ");
v(i) = a(i)/sqrt(sum(a.^2));
end
fprintf("\n Given vector is \n");
disp(a)
fprintf("Direction cosine of the given vector is
\n");
disp(v)
OUTPUT EXAMPLE
>> DirCos
Enter the value of vector : 1
Enter the value of vector : -2
Enter the value of vector : -3
Given vector is
1 -2 -3
Direction cosine of the given vector is
0.26726 -0.53452 -0.80178
THANKS