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

Take the following matrix: A = [16 2 3 13 5 11 0 8 9 7 6 12 4 14 15 1] Write gen

ID: 3785562 • Letter: T

Question

Take the following matrix: A = [16 2 3 13 5 11 0 8 9 7 6 12 4 14 15 1] Write generalized code to find the average value of all sixteen data points stored in the matrix. The program must work even if the initial matrix size changes Then write code to do the following: If the matrix element is lower than the average value, replace it with the value '0' If the matrix element is greater than the average value, replace it with the value '2' If the matrix element is equal to the average value, replace with the value '1' Use 'fprintf' command to display the average value and to state how many matrix elements were the same as the average. Display the final modified A matrix. Taylor series can be used in calculation of different functions in mathematics. The series below is used for evaluation of the sine function for x in radians. sin(x) sigma_n = 1^k (-1)^(n - 1) x^2n - 1/(2n - 1)! = x - x^3/3! + x^5/5! -.. + (-1)^(k - 1) x^2k - 1/(2k - 1)! Write a code that calculates this series for x = pi/6, and calculate the difference between your values and the values given by the MATLAB sine function. I.e. sin (x), for k=1 k=10 k=100 Print out the calculated differences in your code using fprintf. Make sure the program is written in a way that the user can input the x and A values at the beginning. plot the difference between the calculated value for your series and MATLAB sine function sin (x) for k= 1 to k= 10 with an increment of 1 and x = pi/6. Permitted Matlab commands - assignment - use of other commands will result in a grade of zero (0) for the assignment clc clear disp () size () input () if-elseif-else-end for-end while-end fprintf()

Explanation / Answer

PROBLEM 1:

A = input('enter matrix '); %Enter matrix element as [4 5 6;7 8 9]
[rows,cols] = size(A); %Get number of rows and columns in matrix
%Calculate average
average = 0;
for row = 1:rows
for col = 1:cols
average = A(row,col) + average;
end
end
average = average/(rows*cols);
%modify initial matrix
count = 0;
for row = 1:rows
for col = 1:cols
if A(row,col) < average
A(row,col) = 0;
elseif A(row,col) > average
A(row,col) = 2;
else
A(row,col) = 1;
count++;
end
end
end
fprintf('average value of matrix is: %d ',average);
fprintf('Number of matrix element same as average: %d ',count);
fprintf('modified matrix is ')
disp(A);

--------------------------------------------------------------------------------------------------------------------------------------------------------------

PROBLEM 2:

x = input('enter x '); %Enter value of x(enter pi/6 )
k = input('enter k '); %Enter value of y
sum = 0;
%calculate sin(x)
for n = 1:k
%calculate (2n -1)!
factorial = 1;
for val = 2:(2*n - 1)
factorial = factorial * val;
end
sum = sum + (((-1)^(n-1)) *(((x)^(2*n - 1))/factorial));
end
%find the differance
diff = sum - sin(x);
fprintf('differance between calculate and matlab sin(%d) is: %d ',x,diff);

%------------------------------------------------------------

%matlab program to plot differance

x = (pi/6);
sum = 0;
figure %create a graph in new figure window
for k = 1:10
%calculate (2k -1)!
factorial = 1;
for val = 2:(2*k - 1)
factorial = factorial * val;
end
sum = sum + (((-1)^(k-1)) *(((x)^(2*k - 1))/factorial));
  
y = (sum - sin(x)); % get the differance

%plot graph with k in x axis and diff in y axis
plot(k,y); hold on %make "hold" to "on" so that figure is not overwritten with each iteration.
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