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

MATLAB/solving Linear Systems Solve the following linear systems of equations fo

ID: 2963151 • Letter: M

Question

MATLAB/solving Linear Systems



Solve the following linear systems of equations for the given unknowns by setting up the equations in matrix form, Ax = b. Solve in Matlab by using the command x = A whenever possible. Recall that, for the case of an n X n system, a unique solution exists if and only if det A = |A| 0. If the matrix is singular, you can try the rref command. Use Matlab to solve for the steady-state(s) of the system (l)-(3) using the values of the rate constants given in part (e) of Problem 1 above. Compare with the long run of the system found from (9). The m-file for this problem should be a script m-file called HWQ2A.m. A 3 X 3 system with a unique solution 3x1 + x2 - 2X3 = 1 X1 + 2x2 - x3 = 0 2x1 + x3 = -5 The m-file for this problem should be a script m-file called HWQ2B.m. An over specified system with 3 equations and 2 unknowns. The solution in this case is the least squares solution. 4x1 + 2x2 = 3 X1 - X2 = - 1 3x1 - 4x2 = 7 The m-file for this problem should be a script m-file called HWQ2C.m. A singular 3x3 system with an infinite number of solutions; Matlab warns that the matrix is singular. Use the rref command to find all solutions. x1 + 2x2 + 3x3 = 1 Ax1 + 3x2 + 2x3 = 2 5x1 + 5x2 + 5x3 = 3 The m-file should be a script m-file called HWQ2D.m.

Explanation / Answer

clear;

clc;

%for part a

% dcA/dt=-k1 cA+k2 cB (1)

% dcB/dt=k1 cA - (k2+k3) cB+ k4cC (2)

% dcC/dt=k3 cB- k4cC (3)

% k1=2, k2=1, k3=2 , k4=2

% [2 3 10]

% dcA/dt=-2 cA+ cB .... (1)

% dcB/dt=2 cA - (3) cB+ 2 cC (2)

% dcC/dt=2 cB- 2 cC (3)


disp('solution for part a');

A= [ -2 1 0

2 -3 2

0 2 -2];


b=[ 2

3

10];


if(det(A)==0)

disp('the determinant is singular');

end


x=rref([A b])


X=sprintf(' cC = t and cB = %0.2f t and cA = %0.2f t ',x(2,4),x(2,3),x(1,4),-x(1,3));

disp(X);


%for part b--------------------------


A=[3 1 -2

1 2 -1

1 0 1];

b= [1

0

-5];

format shortg;

x=A;

disp('solution for part b');

disp(x);

% for part c------------------------

clear A b x;

A= [ 4 2

1 -1

3 -4];

b= [3

-1

7];


x= A;

disp('solution for part c');

disp(x);


%for part d------------------------------

disp('solution for part d');

clear A b x

A=[1 2 3

4 3 2

5 5 5];

if(det(A)==0)

disp('the determinant is singular');

end

b= [1

2

3];


x=rref([A b])


X=sprintf('here x3 = t and x2 = %0.2f - %0.2ft and x1 = %0.2f + %0.2ft',x(2,4),x(2,3),x(1,4),-x(1,3));

disp(X);





%---------------------------output window-------------------------------------------------------------------------------


solution for part a

the determinant is singular


x =


1 0 -0.5 0

0 1 -1 0

0 0 0 1


cC = t and cB = 0.00 t and cA = -1.00 t

cC = t and cB = 0.00 t and cA = 0.50 t


solution for part b

-1.625

-0.875

-3.375


solution for part c

1.0883

-0.74088


solution for part d


the determinant is singular


x =


1 0 -1 0.2

0 1 2 0.4

0 0 0 0


here x3 = t and x2 = 0.40 - 2.00t and x1 = 0.20 + 1.00t