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

Matlab help please For a square matrix A (i.e dimensions nxn), the matrices of s

ID: 3403480 • Letter: M

Question

Matlab help please

For a square matrix A (i.e dimensions nxn), the matrices of sin(A) and cos(A) can be obtained as follows (-1) cos( A I (2k)! A3 A5 A7 2k+1 (-1) sin (A) A Where I is the nxn identity matrix (diagonals terms are all equal to 1 and off-diagonal terms are all equal to zero) 2k+1 The partial sums CN (A 30-1) and S (A (-1) can thus be used to 2k +1)! k-0 approximate the matrices sin(A) and cos(A) respectively 1. Write a Matlab function matcosin' having for input a square matrix A and for output the matrices cos(A) and sin(A). Use a control flow block (for, if or while) to compute the partial sums CN (A) and Sw (A) for a sequence of N 0,1,2 etc. Stop the loop once the following criterion is fulfilled max (CN I (A)-CN (A), SNI (A)-SN s0.01 (A)) N.B: cos(A) is NOT the matrix obtained by computing the cosine of the individual elements of the matrix A. 2. Let a, a 22 Where a, I, a12, ah, and ana are the last four digits of your student ID a. Use the function matcosin to compute cos(A) and sin(A) b. Compute (cos(A) (sin(A))?

Explanation / Answer

The function is

function [cos_A,sin_A]=matcosin(A)
%%
I=eye(size(A)); % Identity Matrix
cos_N_plus_1=0;
sin_N_plus_1=0;
cos_N=0;
sin_N=0;
tolerance=0.01;
for k=0:10000
cos_N_plus_1=cos_N+(((-1)^k)*(A^(2*k))*(1/factorial(2*k)));
error_cos=abs(cos_N_plus_1-cos_N);
  
sin_N_plus_1=sin_N+(((-1)^k)*(A^(2*k+1))*(1/factorial(2*k+1)));
error_sin=abs(sin_N_plus_1-sin_N);
  
max_error=max(error_cos,error_sin);
  
if max_error<=tolerance
break
end
cos_N=cos_N_plus_1;
sin_N=sin_N_plus_1;
end

fprintf 'cos(A) is %f and sin(A) is %f ',cos_N, sin_N
cos_A=cos_N;
sin_A=sin_N;

#####################################################################################

save the above function as matcosin.m file.

The seocnd part of the question can be done by creating your own matrix

Here Assuming the last 4 digits are 1021

we have :

clear all
clc

%%

A=[1,2;0,1];

[C,S]=matcosin(A)

sum=(C^2+S^2)