Page 289 - MATLAB an introduction with applications
P. 289
274 ——— MATLAB: An Introduction with Applications
%fx0= norm(fx);
for k=1: MaxIter
J=jacob(f,xx(k,:),h,varargin{:});
if rank(J)<Nx
k=k–1; fprintf(‘Warning: Jacobian singular! with det(J)=%12.6e\n’,det(J));
break;
else
dx= –J\fx(:); %–[dfdx]^–1*fx;
end
xx(k+1,:)= xx(k,:)+dx.’;
fx= feval(f,xx(k+1,:),varargin{:}); fxn=norm(fx);
% if fxn<fx0, break; end
%end
if fxn<TolFun|norm(dx)<TolX, break; end
%fx0= fxn;
end
x= xx(k+1,:);
if k==MaxIter
fprintf(‘Do not depend on this, though the best in %d iterations\n’,MaxIter)
end
Example E5.3: Fit a polynomial by quadratic approximation and determine the values of X at which F(X) is
minimum.
X F(X)
1 8
2 3
3 17
Solution:
X F (X)
1 8
2 3
3 17
2
Let F(X) = a + a X + a X . From the given data, we have
0
2
1
a + a + a = 8
2
1
0
a + 2a + 4a = 3
2
0
1
a + 3a + 9a = 17
1
2
0
solving above equations using MATLAB give
>> A=[1 1 1;1 2 4;1 3 9];
>> b=[8;3;17];