Question

In: Civil Engineering

Write a function script DirCos.m that takes a vector (any row or column array) as the...

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

Solutions

Expert Solution

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


Related Solutions

Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and...
Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and returns only the odd index entries. Do this by first setting the even entries to 0, and then removing the 0 entries by using a logical array. The first line of your code should read function p = ReturnOddEntries(p) For example, if you run in the command window p = ReturnOddEntries([1.2 7.1 8.4 -42 100.1 7 -2 4 6]), then you should get p...
Write a function declaration for a function that sums each row of a 2D array, where...
Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. IN C Program.
Write a function declaration for a function that sums each row of a 2D array, where...
Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. Need it in 10 minutes, please.
for input matrix a , write a function to return the element in row 2 column...
for input matrix a , write a function to return the element in row 2 column 3 of that matrix
Which row has the largest sum? Write a method that takes a 2D int array and...
Which row has the largest sum? Write a method that takes a 2D int array and prints: of The index of the row that has the largest sum The sum of elements in that row java
write a function declaration for a 2d array where each row size is 8 and the...
write a function declaration for a 2d array where each row size is 8 and the function does not return anything.
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input #...
How to write a C++ of CountingSort function using 2D vector? CountingSort(vector > array) Input # of rows: 2 Input Row 1: 9 8 7 6 3 2 1 5 4 Input Row 2: 1 2 4 3 5 6 9 8 7 Output 1,2,3,4,5,6,7,8,9 1,2,3,4,5,6,7,8,9
Write a function in C# that takes an array of double as the parameter, and return...
Write a function in C# that takes an array of double as the parameter, and return the average
MATLAB, if-else Write a script which to do the following. Take an array of any size...
MATLAB, if-else Write a script which to do the following. Take an array of any size as input and check if all the elements are integers. (i) If not, display the error message ‘Invalid input!’. Use the error command to create a proper error message in red. (ii) If yes, count the number of rows where the sum of the elements is smaller than the average row sum. It is recommended that you use a test variable with many rows...
Write a function in C that takes one argument, an array of 50 elements. Your function...
Write a function in C that takes one argument, an array of 50 elements. Your function should print out the index and value of the smallest element in the array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT