KETA01 Tenta 2011-03-10 Carmen Arevalo

Contents

format short g

Uppgift 1

A=[ 1 0 -1 0 -1 -1 0 0
    4 0 -2 -2 -2 -4 0 0
    1 2*.21 -1 -1 -2 -1 0 -2
    0 .79 0 0 0 0 -1 0
    1-.33 0 0 0 0 -1 0 0
    -.97 0 1 0 0  .97 0 0
    0 0 1 0 1 1 1 -(1-.138)/.138
    1 0 0 0 0 0 0 0 ]
b=[0 0 0 0 0 0 0 100]'
x=A\b
factor=(sum(x(3:8))-x(4))/100;
For=x(3)/factor
Myr=x(5)/factor
Met=x(6)/factor
Kva=x(7)/factor
Syr=x(8)/factor
A =
  Columns 1 through 7
            1            0           -1            0           -1           -1            0
            4            0           -2           -2           -2           -4            0
            1         0.42           -1           -1           -2           -1            0
            0         0.79            0            0            0            0           -1
         0.67            0            0            0            0           -1            0
        -0.97            0            1            0            0         0.97            0
            0            0            1            0            1            1            1
            1            0            0            0            0            0            0
  Column 8
            0
            0
           -2
            0
            0
            0
      -6.2464
            0
b =
     0
     0
     0
     0
     0
     0
     0
   100
x =
          100
       395.13
        32.01
           33
         0.99
           67
       312.16
       65.983
For =
       6.6947
Myr =
      0.20705
Met =
       14.013
Kva =
       65.286
Syr =
         13.8

Uppgift 2

f=@(x)x.^3-exp(x)-10*x-7;
xp=linspace(-4,4);
yp=f(xp);
figure(1)
plot(xp,yp)
grid

There are 2 roots, near -3 and -1

x1=fzero(f,-3)
x2=fzero(f,-1)
a=quad(f,x1,x2)
x1 =
      -2.7209
x2 =
     -0.79547
a =
        6.387

Uppgift 3

dat=importdata('production_cost_data.txt');
run=dat.data(:,1);
cost=dat.data(:,2);
figure(2)
plot(run,cost,'o')

Using Basic Fitting we see that a straight line is the best choice because taking a higher degree polynomial does not reduce the residual substancially

The data is fitted by y = p(1) x + p(2), where x is the run and y is the cost.

p=polyfit(run,cost,1)
runp=linspace(min(run),max(run));
costp=polyval(p,runp);
figure(3)
plot(run,cost,'o',runp,costp)
legend('data','fit','Location','best')
xlabel('run')
ylabel('cost')
p =
       8.7116       4016.8