Page 291 - MATLAB an introduction with applications
P. 291

276 ———  MATLAB: An Introduction with Applications

                                        2
                   Let F(X) = a + a X + a X .  From the given data, we have
                                      2
                             0
                                 1
                             a + a  + a  2     = –7
                            0
                                1

                          a + 2a  + 4a = 5
                                     2
                                1
                           0

                          a + 3a  + 9a = 14
                                1
                           0
                                     2
                   Solving above equations give
                                    a  = –22
                                     0
                                    a  = 16.5
                                     1
                                    a  = –1.5
                                     2
                   >> x=[1 2 3];y=[–7 5 14];a2a1a0=polyfit(x,y,2)
                   a2a1a0 =
                          –1.50000000000000      16.50000000000002     –22.00000000000003
                   and the function is
                          F(X) = –22 + 16.5X – 1.5X 2

                                                                                      dF ()
                                                                                         X
                                                                                                 −
                   For finding minimum of the function, we find the first derivative of the function    = 16.5 3X = ;
                                                                                                       0
                                                                                       dX
                   for a minimum or maximum
                   thus, X = 5.5
                                                                                   2
                                                                                     ()
                                                                                  dF X
                                                                                             <
                   To check for minima or maxima, we find second derivative of the function   =− 30 ; thus it’s a
                                                                                   dX  2
                   maximum.
                   Thus, for the given function there is no absolute minimum. The function attains its minimum values at  ±∞ .
                   MATLAB Solution:
                   % Problem 3.2
                   clc
                   clear
                   disp(‘Fit a Polynomial by Quadratic Aproximation’)
                   x1=1;
                   x2=2;
                   x3=3;
                   f1=–7;
                   f2=5;
                   f3=14;
                   fx1=[1 x1 (x1)];
                   fx2=[1 x2 2*x2];
                   fx3=[1 x3 3*x3];
                   a=[fx1;fx2;fx3]
                   b=[f1 ;f2; f3]
                   poly_values=inv(a)*b
   286   287   288   289   290   291   292   293   294   295   296