HW5

docx

School

University of Florida *

*We aren’t endorsed by this school

Course

3344

Subject

Mathematics

Date

Apr 3, 2024

Type

docx

Pages

7

Uploaded by KidArt5006

Report
HW#5 Problem 1. We need to find p 3 given p 0 = [ 0 0 1 ] p 1 = [ 0 0 1 ] [ 0.95 0 0.05 0.25 0.5 0.25 0.1 0 0.9 ] ¿ [ 0 0.95 + 0 0.25 + 1 0.1 0 0 + 0 0.5 + 1 0 0 0.05 + 0 0.25 + 1 0.9 ] ¿ [ 0.1 0 0.9 ] p 2 = [ 0.1 0 0.9 ] [ 0.95 0 0.05 0.25 0.5 0.25 0.1 0 0.9 ] ¿ [ 0.1 0.95 + 0 0.25 + 0.9 0.1 0 0.1 0.05 + 0 0.25 + 0.9 0.9 ] ¿ [ 0.185 0 0.815 ] p 3 = [ 0.185 0 0.815 ] [ 0.95 0 0.05 0.25 0.5 0.25 0.1 0 0.9 ] ¿ [ 0.25725 0 0.74275 ] p 3 ¿ [ 0.25725 0 0.74275 ] Problem 2 . [ 2 0 1 0 2 0 0 1 0 2 1 0 3 1 0 0 ][ 29 5 3 8 ] R 3 1 2 R 1 [ 2 0 0 0 2 0 1 1 0 2 1 0 3 1 1.50 0 ][ 29 5 11.5 8 ]
R 4 R 2 [ 2 0 0 0 2 1 1 0 0 0 1 2 3 0 1.50 1 ][ 29 8 11.5 5 ] R 3 + R 2 [ 2 0 0 0 2 1 0 0 0 0 1 2 3 0 1.50 1 ][ 29 8 3.5 5 ] R 4 ¿ 2R 3 [ 2 0 0 0 2 1 0 0 0 0 1 0 3 0 1.50 4 ][ 29 8 3.5 12 ] Back-substitution { 2 x 1 + 2 x 2 + 3 x 4 = 29 x 2 = 8 x 3 1.5 x 4 =− 3.5 4 x 4 = 12 { x 1 = 29 2 8 3 3 2 = 2 x 3 = 1.5 3 3.5 = 1 x 4 = 3 x 2 = 8 Amount of each compound contained in the sample. NaMgSi 2 O 6 2 CaFeSi 2 O 6 8 NaMgAl 2 O 6 1 KALSi 3 O 6 3 Problem 3 .
P = [ 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 ] U = [ 2 0 0 0 2 1 0 0 0 0 1 0 3 0 1.50 4 ] L = [ 1 0 0.5 0 0 1 1 0 0 0 1 2 0 0 0 1 ] Problem 4. See gauss_elim.m Problem 5. See lu_fact.m Problem 6. See hw5_p6.m Problem 7. See vector_norm.m Problem 8. As you can see, the output below shows the norms of Pink, Magenta and Purple when the color code of each is used as a row vector with three values. Pink, Magenta, Purple 1-norms: 540, 510, 256 2-norms: 329.317, 360.624, 181.019 inf-norms: 255, 255, 128 From the fact that magenta is closer to pink numerically in all three commonly used norms we can conclude that magenta is “closer” to pink. Problem 9. Here is my “Sun Salutation” sequence, and the video of me performing is attached. 1. Mountain 2. Forward fold 3. Chaturanga 4. Cobra 5. Down Dog 6. Forward Fold 7.Halfway lift 8. Forward Fold 9. Mountain
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Problem 4. function [ x ] = gauss_elim( A, b ) %%gauss_elim uses Gauss elimination with partial pivoting to solve Ax = b %%Inputs: A - A matrix % b - b vector %%Outputs: x - solution to Ax = b %%Author: Aleksandr Mnatsakanyan n = size(A,1); % the size of the A matrix x = zeros(n,1); % preallocation of the x vector sum = 0; % used for back-substitution, could have used backslash but did it this way anyways for i = 1:n-1 % for loop to go through all the columns up to one before the last one [~,max_val] = max(abs(A(i:n,i))); % getting the index of the biggest absolute value of the column i max_val = max_val + i - 1; % correcting the index % if the max value index matches the current i value that means that % our pivot element is the greatest if not, we need to pivot if max_val ~= i pivot = [i max_val]; % creating the pivot vector else pivot = [i i]; % creating the pivot vector
end if pivot(1) ~= pivot(2) % if pivoting is needed, we create temporary variables for A and b TempA = A; Tempb = b; % then we use them as reference for the new pivoted A and b A(pivot(1),:) = TempA(pivot(2),:); A(pivot(2),:) = TempA(pivot(1),:); b(pivot(1)) = Tempb(pivot(2)); b(pivot(2)) = Tempb(pivot(1)); end % eliminating the variables below the current pivot element for ii = i+1:n b(ii) = b(ii)-(A(ii,i)/A(i,i)).*b(i); A(ii,:) = A(ii,:)-(A(ii,i)/A(i,i)).*A(i,:); end end % backsubstitution for k = n:-1:1 for kk = 1:n sum = sum + A(k,kk)*x(kk); % this is the sum of all elements of a row other than the needed x(i) so the row looks like sum + a(ij) * x(i) = b(i) end x(k) = (b(k) - sum)/A(k,k); % solving the row for x(i) sum = 0; % resetting the value of the sum end Problem 5. function [ L, U, P ] = lu_fact( A ) %lu_fact performs LU factorization with partial pivoting %Input: A - A matrix to be factored %Outputs: L - lower-triangular matrix % U - upper-triangular matrix % P - permutation matrix associated with pivots %Author: Aleksandr Mnatsakanyan L = diag(ones(size(A,1),1)); P = L; n = size(A,1); % this part of the code is the same as gauss_elim with the addition of an % if statement. for i = 1:n-1 [~,max_val] = max(abs(A(i:n,i))); max_val = max_val + i - 1; if max_val ~= i pivot = [i max_val]; else
pivot = [i i]; end if pivot(1) ~= pivot(2) TempA = A; TempP = P; if pivot(1) >= i && pivot(1) > 1 % we need to check if the pivoting of the L matrix is going to affect the identity matrix(middle diagonal of 1s) % same pivoting code as in gauss_elim TempL = L; L(pivot(1),1:pivot(1)-1) = TempL(pivot(2),1:pivot(1)-1); L(pivot(2),1:pivot(1)-1) = TempL(pivot(1),1:pivot(1)-1); end A(pivot(1),:) = TempA(pivot(2),:); A(pivot(2),:) = TempA(pivot(1),:); P(pivot(1),:) = TempP(pivot(2),:); P(pivot(2),:) = TempP(pivot(1),:); end for ii = i+1:n L(ii,i) = A(ii,i)/A(i,i); % substituting the coefficient into matrix L A(ii,:) = A(ii,:)-(A(ii,i)/A(i,i)).*A(i,:); end end U = A; % needed for the output, as the final A matrix is what U needs to be end Problem 6. clc; clear; A = [2 2 0 3; 0 0 2 1; 1 0 1 0; 0 1 0 0]; % initial matrix n = size(A,1); % getting the size of A b = diag(ones(n,1)); % Identity matrix of the same size as A [L,U,P] = lu(A); I = zeros(n,n); % preallocating the inverse matrix d = zeros(n,1); % preallocating the modified b vector, d for i = 1:n d = L\(P*b(:,i)); % solving for d x = U\d; % solving for x I(:,i) = x; % substituting the vector into the corresponding column of the Inverse matrix end
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Problem 7. function [norm_val] = vector_norm(x,normnum) %%calc_norm computes the 1-, 2-, or infinity-norm of a vector %%Inputs: x - vector whose norm is to be calculated % normnum - which norm is to be computed %%Output: norm_val - computed norm value %%Author: Aleksandr Mnatsakanyan % I think this code is pretty self-explanatory if normnum == 1 norm_val = sum(abs(x)); elseif normnum == 2 norm_val = sqrt(sum(x.^2)); else norm_val = max(abs(x)); end end