Starting from:

$25

Math551 - lab02 - Solved

Goals: In this assignment you will learn how to determine whether a system of linear equations has a solution, how to reduce a system to a row echelon form and how to visualize the solution. During the lab session, your lab instructor will teach you the necessary Matlab code to complete the assignment, which will be discussed in the lab.

To get started: Create a new Matlab script file and save it as “lab02.m”.

Matlab commands to learn: magic, rref, rank, transpose, plot, figure, hold on, grid on, grid off, subplot, meshgrid, surf, view

What you have to submit: The file lab02.m, which you will create during the lab session.


Variables: x1, A, q
At times you will also be asked to answer questions in a comment in your M-file. You must format your text answers correctly. Questions that you must answer are shown in gray boxes in the lab. For example, if you see the instruction

Q7: What does the Matlab command lu do? your file must contain a line similar to the following somewhere

% Q7: It computes the LU decomposition of a matrix.

The important points about the formatting are

•    The answer is on a single line.

•    The first characters on the line is the comment character %.

•    The answer is labeled in the form Qn:, where n stands for the question number from the gray box.

If you do not format your answers correctly, the grading software will not find them and you will lose points.

TASKS

1. Create a 5 × 5 matrix A using the magic command. Type help magic in the command line to learn about the magic command.

Variables: A
2.       Create a column-vector B with entries 1,3,2,−1,4. Variables: B

3.       Create a matrix M by adding the vector B as the last column of the matrix A. Variables: M

4.       Check the rank of A and M using the rank command. Type help rank in the command line to learn about the rank command.

Variables: rank A, rank M
 
Q1: Is the system with augmented matrix M consistent?
5.       Produce a reduced row echelon form of M by using the rref command. Type help rref in the command line to learn about the rref command. Variables: rref M

6.       Create a 7 × 7 matrix C using the rand command. Type help rand in the command line to learn about the rand command. Variables: C

7.       Create a row vector D with 7 elements using the rand command. Variables: D

8.       Apply the transpose command to D. Type help transpose in the command line to learn about the transpose command.

Variables: transpose D
 
Q2: What does the transpose command do?
9.       Create an augmented matrix N of the system with coefficient matrix C and right-hand side D. Variables: N

10.   Apply the rref command to N.

Variables: rref N
11.   Consider the system of two equations:

( x + 2y = 3 x − y = 0

Plot the lines representing each of the equations on one graph using the plot command on the interval [0,5]. Use the color red for the first equation and the color blue for the second.

Type in the commands

1
figure;
2
x = [0:0.1:5];
3
y1=(3-x)/2;
4
y2=x;
5
plot(x,y1,'red');
6
hold on;
7
plot(x,y2,'blue');
8
grid on;
 

12.   Consider the system

 2x + y + z = 4



−x + y − z = 1

3x + 2y − z = 6

Note that this system of equations cooresponds to the following augmented matrix:

 

Type in the commands

1
figure;
2
[x,y]=meshgrid(-5:0.1:5,-5:0.1:5);
3
z1=4-2*x-y;
4
z2=-x+y-1;
5
z3=3*x+2*y-6;
6
surf(x,y,z1);
7
hold on;
8
surf(x,y,z2);
9
hold on;
10
surf(x,y,z3);
 
Q8: What does the meshgrid command do?
 
 
Q9: What does the surf command do?
 
 
 
 
 
 
 
13.   Come up with three systems of linear equations in three variables (with three equations each) representing all possible situations: no solution, a unique solution, infinitely many solutions. For each system of equations, create the corresponding augmented matrix, respectively naming them no sol, uni sol, inf  sol. Apply the commands above to produce a visual picture for each of the systems (each on a separate figure). Use appropriate limits for variables x and y and a command view to present each case clearly.

Variables: no sol, uni sol, inf sol

More products