Use MATLAB to determine how many elements are in the array cos(0):0.04:log10(200
ID: 3844848 • Letter: U
Question
Use MATLAB to determine how many elements are in the array cos(0):0.04:log10(200). Determine the 30^th element. ans = 33 ans = 2.1600 Sometimes it is convenient to have a table of sine, cosine, and tangent values instead of using a calculator. Create a table of all three of these trigonometric functions for angles from 0 to 2 pi, with a spacing of pi/6 radian. Your table should contain a column for the angle and then for the sine, cosine, and tangent. Use 'disp' command. Define the following two arrays A=[10 2 3 40] B=[15 6 27 8] Find array P by stacking arrays A and B horizontally Find array Q by stacking arrays A and B vertically Find element by element array multiplication of A and B, call the resulting vector as R Sort array A in 'descending' order, call the resulting vector as SExplanation / Answer
Here is the code for you:
a = cos(0):0.04:log10(200);
length(a)
a(30)
%cos(0) is 1. log10(200) = 2.301
%And the range of these numbers should be divided into parts,
%with interal 0.04.
%Which means, 1, 1.04, 1.08, ..... till 2.28.
%Therefore, the number of elements in the array are: 33.
%And the element at 30th position is: 2.1600
x = 0:pi/6:2*pi; %Creates an array of 0 to 2*pi radians with a spacing of pi/6.
%The below logic will print the table.
for i = 1 : length(x)
result = [x(i) sin(x(i)) cos(x(i)) tan(x(i))];
disp(result);
end
A = [10 2 3 40];
B = [15 6 27 8];
P = [A B];
Q = [A; B];
R = A .* B;
S = sort(A, 'descend')
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.