/* ==================================== */ /* Linear Least Square Fit to Data in Table 6.1 of Bevington and Robinson. The data is the voltage vs position along a wire, and is fit to a model of V[i] = a*x[i] + b */ /* In math sum is a linear function, but maxima is very conservative. By * default, it assumes sum *might* be non-linear */ declare(sum,linear); /* Set the data */ n : 9; V : [0.37, 0.58, 0.83, 1.15, 1.36, 1.62, 1.90, 2.18, 2.45]; x : [10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0]; %sigma : [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05]; /* Define a chi2 to find the general solution. */ chi2: sum((V[i] - a*x[i] - b)^2/%sigma[i]^2, i, 1, n); /* Find the derivatives wrt a and b */ Dchi2Da : expand(diff(chi2,a)); Dchi2Db : expand(diff(chi2,b)); /* Invert the error matrix (or inverse covariance) to find the covariance. */ cov : invert(matrix( [diff(Dchi2Da,a), diff(Dchi2Da,b)], [diff(Dchi2Db,a), diff(Dchi2Db,b)]) / 2); /* Solve for the parameters at the minimum chi2 value*/ soln: float(solve([Dchi2Da=0, Dchi2Db=0], [a,b])); /* Calculate the minimum chi2 value. */ float(ev(chi2, soln[1][1], soln[1][2]));