Question: Numerical optimization for two parameters in a loop

Hi

I am attempting to do a least squares regression with two variable (HK and S) generating my curve.  The equations are extremely tempermental and won't allow maple to solve them using normal methods, so I'm resorting to numerical methods to minimize the least squares.

I am attempting to create a dataset that I can search for the minimum of "k" and have it tell me what "i" and "j" values I used to get there.  The code below is the basic idea, the actual equations are more much more intensive and the search range will be much larger (1000 by 2000).

I see two problems with my code. First, I can't figure out how to get the array properly indexed for i and j because they are not whole numbers and secondly, I can't figure out how get the output (print i,j,k) into a searchable form to look for the minimum.

X := [.24, .28, .35, .40, .60];
Y := [.69, .75, .80, .83, .87];
A := 1+FIO2*HK*S;

for i from .3 by 0.5e-1 to .35 do
for j from .2 by 0.5e-1 to .25 do

A1 := subs(HK = i, S = j, A);
Q := subs(FIO2 = X[1], A1)-Y[1];
R := subs(FIO2 = X[2], A1)-Y[2];
T := subs(FIO2 = X[3], A1)-Y[3];
U := subs(FIO2 = X[4], A1)-Y[4];
V := subs(FIO2 = X[5], A1)-Y[5];
k := Q^2+R^2+T^2+U^2+V^2;
print (i,j,k);

end do
end do

as an asside, anyone know why this code (below) substituted for Q-->print (i,j,k) (above) works so much faster?

for n from 1 to 5 do
M[n]:=subs(FIO2=X[n],A1)-Y[n];
end do
kk:=add(M[n]^2,n=1..5);
print (i,j,kk);

thanks for all your help

Please Wait...