{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

che310hw1

# che310hw1 - Ch E 310 Fall 2008 Homework 1 Solutions hw1_1.m...

This preview shows pages 1–3. Sign up to view the full content.

Ch E 310 – Fall 2008 - Homework 1 Solutions hw1_1.m % generate matrices using colon operator A(:,1) = [1:5]; A(:,2) = [3:3:15]; A(:,3) = [2:2:10]; B(1,:) = [1:4]; B(2,:) = [8:-1:5]; B(3,:) = [1:2:7]; C = zeros(5,4); % initialize 5x4 matrix C for i = 1:5 % loop over all rows in A for j = 1:4 % loop over all columns in B for k = 1:3 % loop over all columns in A C(i,j) = C(i,j) + A(i,k) * B(k,j); % use formula definition end end end % report output disp( 'this is C based on the formula:' ) C disp( 'this is C based on the MATLAB * operator:' ) C2 = A*B Output: >> hw1_1 this is C based on the formula: C = 27 29 31 33 54 58 62 66 81 87 93 99 108 116 124 132 135 145 155 165 this is C based on the MATLAB * operator: C2 = 27 29 31 33 54 58 62 66 81 87 93 99 108 116 124 132 135 145 155 165

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
hw1_2.m R = 8.314; E = 1e5; A = 7e16; % define variables rate = @(T) A*exp(-E./(R*T)); % define function handle for k T = linspace(273,400,10); % create temp vector k = rate(T); % calculate rates based on temps subplot 211 % generate subplot with k vs. T fplot(rate,[273 400], 'g-' ) xlabel( 'temperature, K' ) ylabel( 'rate, 1/s' ) title( 'k vs. T' ) subplot 212 % generate subplot with k vs. 1/T semilogy(1./T,rate(T), 'g-' ) xlabel( 'inverse temperature, 1/K' ) ylabel( 'rate, 1/s' ) title(
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}