objectiveFunction(x,StdRes, StdTherm_Val, StdTherm_Beta,Tdata,Vdata)

function G = objectiveFunction(x,StdRes, StdTherm_Val, StdTherm_Beta,Tdata,Vdata)
%OBJECTIVEFUNCTION Objective function for the thermistor problem
% OBJECTIVEFUNCTION(X, STDRED, STDTHERM_VAL, STDTHERM_BETA, TDATA, VDATA)
% calculates the sum of squared error between the VDATA voltage curve and
% the simulated curve. TDATA is the temperature data corresponding to
% VDATA. STDRES, STDTHERM_VAL, and STDTHERM_BETA are values of the
% available resistor and thermistor components. X is a vector of
% integers used to index into the resistor and thermistor vectors.
%
% Sytnax
% G = peaksCon(x, StdRes, StdTherm_Val, StdTherm_Beta,Tdata,Vdata)
%
% See also RunThermistorExample
% Copyright (c) 2012, The MathWorks, Inc.
% All rights reserved.
% StdRes = standard vector of resistor values
% StdTherm = standard matrix (2xN) of themistor values
% Extract component values from tables using integers in x as indices
y = zeros(8,1);
y(1) = StdRes(x(1));
y(2) = StdRes(x(2));
y(3) = StdRes(x(3));
y(4) = StdRes(x(4));
y(5) = StdTherm_Val(x(5));
y(6) = StdTherm_Beta(x(5));
y(7) = StdTherm_Val(x(6));
y(8) = StdTherm_Beta(x(6));
% Calculate temperature curve for a particular set of components
F = tempCompCurve(y, Tdata);
% Compare simulated results to desired curve
Residual = F(:)  Vdata(:);
Residual = Residual(1:2:26);
G = Residual'*Residual; % sum of squares

