Back to tutorial index

Lab 7 Solutions


Topics in this lab

Introduction

It appears that this lab does not have solutions or they are not yet posted.

Back to the top

Exercise 1

A = [1 -1;
    3 5];
b = [5;1];

x = A\b
x =

    3.2500
   -1.7500

Back to the top

Exercise 2

A = [1 -1 3;
    3 5 -1;
    0 5 -3];
b = [5;1;-22];

x = A\b
x =

   10.3846
   -6.8462
   -4.0769

Back to the top

Exercise 3

A = [1 -4 4;
    -1 1 -2;
    1 1 -1];
b = [0; 1; -2];

x = A\b
x =

   -1.6000
   -0.2000
    0.2000

Back to the top

Exercise 4

x = [1,2,3];
y = [3,5,-1];

A = [x(:).^2 x(:) ones(3,1)];
b = y(:);

p = A\b
p =

   -4.0000
   14.0000
   -7.0000

Back to the top

Exercise 5

z = ones(5,1);
A = spdiags([z -2*z z],-1:1,5,5);
b = ones(5,1);

A
full(A)

x = A\b
A =

   (1,1)       -2
   (2,1)        1
   (1,2)        1
   (2,2)       -2
   (3,2)        1
   (2,3)        1
   (3,3)       -2
   (4,3)        1
   (3,4)        1
   (4,4)       -2
   (5,4)        1
   (4,5)        1
   (5,5)       -2


ans =

    -2     1     0     0     0
     1    -2     1     0     0
     0     1    -2     1     0
     0     0     1    -2     1
     0     0     0     1    -2


x =

   -2.5000
   -4.0000
   -4.5000
   -4.0000
   -2.5000

Back to the top

Exercise 6

(Left as homework exercise)

Back to the top

Exercise 7

(Left as homework exercise)

Back to lab exercises.

Back to the top

Get the code

Do you want to try the above code fragments on your own? Download the Matlab script that produces this page here. (lab_7_solns.m)

Powered by MathJax

Published with MATLAB® 8.5