An interactive introduction to MATLAB

(Jeff_L) #1
1.5solving systems of linear equations 15

Exercise 2: Variables and arrays



  1. Create the variables to represent the following matrices:


A=

[

12 17 3 4

]

B=






5 8 3

1 2 3

2 4 6




 C=






22

17

4






a)Assign to the variablex1the value of the second column of matrix
A.
b) Assign to the variablex2the third column of matrixB.
c) Assign to the variablex3the third row of matrixB.
d) Assign to the variablex4the first three values of matrixAas the
first row, and all the values in matrixBas the second, third and
fourth rows.


  1. If matrix A is defined using the MATLAB code
    A = [1 3 2; 2 1 1; 3 2 3], which command will produce the
    following matrix?


B=


3 2

2 1




  1. Create variables to represent the following matrices:


A=






1 2 3

2 2 2

−1 2 1




 B=






1 0 0

1 1 0

1 1 1




 C=






1 1

2 1

1 2






a)Try performing the following operations:A+B,A*B,A+C,B*A,B−A,
A*C,C−B,C*A. What are the results? What error messages are
generated? Why?
b) What is the difference betweenA*BandA.*B?


  1. Solve the following systems of linear equations. Remember to verify your
    solutions.
    a)


−2x+y= 3
x+y= 10
Free download pdf