In: Advanced Math
Use one MATLAB statement to generate each of the following scalars and vectors. (These parts are sequential)
a.) Generate the vector x=(sin5,sin10,sin15,...,sin200) but dont print
b.)Find the Max value in X and which index has this value. Print both the index and the value using Disp (so you can use 2 statements)
c.)Find the minimum value x and which index has this value. Print both the index and the value using Disp (so you can use 2 statements)
d.)Find the difference between the max and min values
e.) find the sum of all the elements of x
f.)find the sum of the absolute value of all the succesive elements of x
g.) find the differences between all the successive elements of x
h.)Find the absolute differences between all the successive elements of x
k.) sort all these elements in increasing order. print this out in two columns. The first containing the values and the second containing the indicies in x where these values occur (so you can use 2 statements.)
l.) Print out the product of all the elements in x, the mean value of these elemnets and their srtandard deviation, and only 1 statement is allowed.
Code in MATLAB :
A = zeros(20,1);
for i=1:20
A(i)= sin(5*i);
end
maximum = max(A);
max_index = find(A == maximum);
disp(maximum);
disp(max_index);
minimum = min(A);
min_index = find(A ==minimum);
disp(minimum);
disp(min_index);
difference = maximum - minimum;
sum_A = sum(A);
absolute_sum_A = (sum(abs(A)));
A_differences = zeros(19,1);
A_abs_differences = zeros(19,1);
for i=1:19
A_abs_differences(i) = abs(A(i+1)-A(i));
A_differences(i) = (A(i+1)-A(i));
end
A_sorted = sort(A);
A_sorted_index = zeros(20,1);
for i=1:20
A_sorted_index(i) = find(A == A_sorted(i));
end
disp(A_sorted);
disp(A_sorted_index);
product = 1;
for i=1:20
product = product*A(i);
end
mean_value = mean(A);
standard_deviation = std(A);
fprintf('The product is %f \nMean value is %f\nStandard Deviation is %f\n',product,mean_value,standard_deviation);