Technological University of the Philippines
Taguig Campus
           LABORATORY
                IN
         NUMERICAL METHOD
             Submitted by:
               BSECE2A
           Balderama, Jannica
             Honrado, Jasper
            Rey, Ann Jessiere
             Ruiz, Muel Fred
           Turallo, Mira Shaine
            Vierneza, Kenneth
             Submitted to:
         Engr. Marcelo V. Rivera
          Date: March 25, 2017
BISECTION METHOD
Script:
syms x;                                           for ctr = ctr : -1 : 2
prompt = 'Please input a function: ';                iteration = iteration + 1
f(x) = input (prompt);                               if ((f(XL))*(f(XM))) < 0
prompt = 'Please input a value of XL: ';                 XL = XL
XL = input (prompt);                                     XU = XM
prompt = 'Please input a value for XU: ';                XM1 = (XL + XU)/2;
XU = input (prompt);                                     XMN = vpa(XM1, 6)
prompt = 'Please input the number of                     ARTE = (abs((XM1 - XM)/XM1))*100;
iterations to be used: ';                                ARTE = vpa(ARTE, 4);
ctr = input (prompt);                                    s = char (ARTE);
chk = 0;                                                 ARTE = [s, ' %']
for chk = chk : 1 : 10                                   XM = XM1;
   if ((f(XL))*(f(XU))) < 0                          elseif ((f(XL))*(f(XM))) > 0
       chk = 10;                                         XL = XM
   elseif ((f(XL))*(f(XU))) > 0                          XU = XU
       disp ('Please input a new value for XL            XM1 = (XL + XU)/2;
and XU')                                                 XMN = vpa (XM1, 6)
       prompt = 'Please input a value of XL: ';          ARTE = (abs ((XM1 - XM)/XM1))*100;
       XL = input (prompt);                              ARTE = vpa (ARTE, 4);
       prompt = 'Please input a value for XU:            s = char (ARTE);
';                                                       ARTE = [s, ' %']
       XU = input (prompt);                              XM = XM1;
   end                                               else
end                                                      ctr = 1
iteration = 0;                                       end
XM = (XL + XU)/2                                  end
Sample:
Please input a function: (x^3)-                   XU = 0.1100
(0.165*x^2)+3.993*(10^-4)                         XMN = 0.0825
Please input a value of XL: 0                      ARTE = 33.33 %
Please input a value for XU: 0.11                 iteration = 2
Please input the number of iterations to be       XL = 0.0550
used: 3                                           XU = 0.0825
XM = 0.0550                                       XMN = 0.06875
iteration = 1                                     ARTE =20.0 %
XL = 0.0550
GAUSSIAN ELIMINATION
Script:
clc ;                                      a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j, j));
%input                                  end
disp 'Gaussian Elimination Method'   end
a = [25 5 1 106.8                    x=zeros(1 , m);
     64 8 1 177.2                    for s=m:-1:1
   144 12 1 279.2];                     c=0;
[m,n]=size(a);                          for k=2:m
for j=1:m-1                                c=c+a(s,k)*x(k);
   for z=2:m                            end
      if a(j, j)==0                     x(s)=(a(s,n)-c)/a(s,s);
          t=a(j,:);a(j,:)=a(z,:);    end
          a(z,i)=t;                  disp('Gauss elimination method ;')
      end                            a
   end                               x'
   for i=j+1:m
Sample:
Gaussian Elimination Method
Gauss elimination method ;
a=
  25.0000 5.0000 1.0000 106.8000
     0 -4.8000 -1.5600 -96.2080
     0     0 0.7000 0.7600
ans =
   0.2905
  19.6905
   1.0857
GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING
Script:
a=[0.25 -1.32 3 20                                  b(i,:)=b(i,:)-b(j,:)*(b(i,j)/b(j,j));
  1.39 2.71 9.63 34                              end
   0.41 2.24 -11 5];                          end
%Gaussian Elimination With Partial Pivoting   x=zeros(1,m);
disp(a) ;                                     for s=m:-1:1
b = sortrows(a, -1)                              c=0;
%disp (b) ;                                      for k=2:m
[m,n]=size (b) ;                                    c=c+b(s,k)*x(k);
for j=1 :m-1                                     end
   for z=2:m                                     x(s) = (b(s,n)-c)/b(s,s);
      if b(j,j)==0                            end
          t=b(j,:);b(j,:)=b(z,:);             disp('Gauss Eliminaton Method With Partial
          b(z,i)=t;                           Pivoting:');
      end                                     b
    end                                       x'
   for i=j+1:m
Sample:
                                              Gauss Eliminaton Method With Partial
  0.2500 -1.3200 3.0000 20.0000               Pivoting:
  1.3900 2.7100 9.6300 34.0000
  0.4100 2.2400 -11.0000 5.0000               b=
                                                1.3900 2.7100 9.6300 34.0000
b=                                                 0 1.4406 -13.8405 -5.0288
                                                   0 0.0000 -16.0961 7.5759
  1.3900 2.7100 9.6300 34.0000
  0.4100 2.2400 -11.0000 5.0000
  0.2500 -1.3200 3.0000 20.0000               ans =
                                                43.3425
                                                -8.0124
                                                -0.4707
NEWTON RHAPSON
Script:
prompt='What is the function?';               vpa (TV , 10)
syms x ;                                      prompt = 'How many iterations?';
f(x) = input(prompt);                         m = input(prompt);
                                              numberofiteration = m
prompt = 'What is the value of x?';
syms y;                                       for numberofiteration = 1: +1 : m
y=input(prompt);                                 numberofiteration
Upper=f(y);                                      TX = f(y)
vpa(TX, 10)                                      TV = diff (f) ;
TV = diff(f);                                    Lower = TV (y)
TV (y);                                          y = y - (TX/TZ)
disp('first derivative is:')                     vpa (y , 10)
TV (y) ;                                      end
Sample:
What is the function?: (x^3)+(4*x^2)-(10)   Upper = 199283/29791
What is the value of x?2.5                  Lower = 21571/961
ans = 30.625                                y = 943980/668701
                                            ans = 1.411662312
first derivative is:
                                            numberofiteration = 3
ans(x) = 3.0*x^2 + 8.0*x
                                            Upper =
How many iterations?3
                                            234521792946912590/299017026184076101
numberofiteration = 3
                                            Lower =
numberofiteration = 1
                                            7723217681040/447161027401
Upper = 245/8
                                            Upper =
Lower = 155/4
                                            705604123360122661/516452338652912904
 y = 53/31
                                            ans =
ans = 1.709677419                           1.36625216
numberofiteration = 2