Code that does the trilinear interpolation for (part of) your problem. 1234567890123456789012345678901234567890123456789012345678901234567890 Unit Algemeen; { General } INTERFACE function trim(S : string) : string; function Getal(lezen : string) : double; IMPLEMENTATION function trim(S : string) : string; { Remove Leading and Trailing Blanks } var L,k,links,rechts : integer; T : string; begin L := Length(S); T := ''; links := 0; rechts := 0; if L > 0 then begin for k := 1 to L do begin if S[k] = ' ' then Continue; links := k; Break; end; if links > 0 then for k := L downto 1 do begin if S[k] = ' ' then Continue; rechts := k; Break; end; end; if links > 0 then T := Copy(S,links,rechts-links+1); trim := T; end; function Getal(lezen : string) : double; { From Text to Number } var regel : string; c : char; k, lengte : integer; effe, delen : double; min, cyfer, punt, goed : boolean; begin regel := trim(lezen); lengte := Length(regel); min := false; if lengte > 0 then if regel[1] = '-' then begin regel := trim(Copy(regel,2,lengte)); min := true; end; punt := false; goed := false; effe := 0; delen := 1; lengte := Length(regel); for k := 1 to lengte do begin if punt then delen := delen * 10; c := regel[k]; cyfer := ((c >= '0') and (c <= '9')); goed := cyfer or (c = '.'); if (not goed) then Break; if (c = '.') then punt := true; if cyfer then effe := effe * 10 + (byte(c) - 48); end; if goed then effe := effe/delen else effe := 0; if min then effe := - effe; Getal := effe; end; END. 1234567890123456789012345678901234567890123456789012345678901234567890 Unit speciaal; { Help with Linear programming problem z=0 x \ y| 0.0 0.2 0.4 0.6 0.8 1.0 -----+------------------------------------ 0.3 | 1.0 1.1 1.1 1.2 1.3 1.3 0.35 | 2.2 2.3 2.5 2.6 2.8 2.9 0.4 | 3.7 3.9 4.2 4.4 4.7 4.9 0.45 | 5.5 5.9 6.2 6.6 7.0 7.3 0.5 | 7.6 8.1 8.6 9.1 9.6 10.1 0.55 | 9.9 10.5 11.2 11.8 12.5 13.2 0.6 | 12.4 13.2 14.0 14.9 15.7 16.5 0.65 | 15.1 16.1 17.1 18.1 19.1 20.1 0.7 | 18.0 19.2 20.4 21.6 22.8 24.0 z=0.16 x \ y| 0.0 0.2 0.4 0.6 0.8 1.0 -----+------------------------------ 0.3 | 1.0 1.1 1.1 1.2 1.3 1.3 0.35 | 2.1 2.3 2.4 2.5 2.7 2.8 0.4 | 3.5 3.7 4.0 4.2 4.4 4.7 0.45 | 5.1 5.5 5.8 6.1 6.5 6.8 0.5 | 7.0 7.5 7.9 8.4 8.9 9.3 0.55 | 7.0 7.5 7.9 8.4 8.9 9.3 0.6 | 7.0 7.5 7.9 8.4 8.9 9.3 } INTERFACE Uses Algemeen; var { Grid Points and Values } xp : array[0..5] of double; yp : array[0..8] of double; zp : array[0..1] of double; fp : array[0..5,0..8,0..1] of double; procedure inlezen(blah : boolean); IMPLEMENTATION procedure inlezen(blah : boolean); { Read Header of this file } var OP : TextFile; regel : string; k,i,j : integer; begin AssignFile(OP,'speciaal.pas'); Reset(OP); for k := 0 to 4 do Readln(OP,regel); zp[0] := Getal(Copy(regel,3,1)); for k := 0 to 1 do Readln(OP,regel); for k := 0 to 5 do begin if blah then Writeln(Copy(regel,10+6*k,3)); xp[k] := Getal(Copy(regel,10+6*k,3)); end; Readln(OP,regel); for j := 0 to 8 do begin Readln(OP,regel); yp[j] := Getal(Copy(regel,1,4)); if blah then Write(yp[j]:7:2); for i := 0 to 5 do begin fp[i,j,0] := Getal(Copy(regel,9+6*i,4)); Write(fp[i,j,0]:7:2); end; Writeln; end; Writeln; for k := 0 to 2 do Readln(OP,regel); zp[1] := Getal(Copy(regel,3,4)); for k := 0 to 2 do Readln(OP,regel); for j := 0 to 6 do begin Readln(OP,regel); for i := 0 to 5 do begin fp[i,j,1] := Getal(Copy(regel,9+5*i,3)); Write(fp[i,j,1]:7:2); end; Writeln; end; { Assume continuous data } for j := 7 to 8 do begin for i := 0 to 5 do begin fp[i,j,1] := fp[i,j-2,1]; Write(fp[i,j,1]:7:2); end; Writeln; end; Writeln; end; END. 1234567890123456789012345678901234567890123456789012345678901234567890 Unit Generaal; { General } INTERFACE Uses speciaal; procedure binnen(x,y,z : double; var i,j,k : integer); procedure opvragen(var x,y,z : double); function trilineair(x,y,z : double; i,j,k : integer) : double; IMPLEMENTATION procedure binnen(x,y,z : double; var i,j,k : integer); { Inside which of the Bricks } var OK : boolean; L,m : integer; begin L := Length(xp); for m := 1 to L-1 do begin OK := (xp[m-1] <= x) and (x <= xp[m]); i := m; if OK then Break; end; L := Length(yp); for m := 1 to L-1 do begin OK := (yp[m-1] <= y) and (y <= yp[m]); j := m; if OK then Break; end; L := Length(zp); for m := 1 to L-1 do begin OK := (zp[m-1] <= z) and (z <= zp[m]); k := m; if OK then Break; end; end; procedure opvragen(var x,y,z : double); { Asking User Values } var L : integer; OK : boolean; begin L := Length(xp); Write('x := ') ; Readln(x); OK := (xp[0] <= x) and (x <= xp[L-1]); while not OK do begin Writeln(xp[0]:5:2,' <= x <= ',xp[L-1]:5:2); Write('x := ') ; Readln(x); OK := (xp[0] <= x) and (x <= xp[L-1]); end; L := Length(yp); Write('y := ') ; Readln(y); OK := (yp[0] <= y) and (y <= yp[L-1]); while not OK do begin Writeln(yp[0]:5:2,' <= y <= ',yp[L-1]:5:2); Write('y := ') ; Readln(y); OK := (yp[0] <= y) and (y <= yp[L-1]); end; L := Length(zp); Write('z := ') ; Readln(z); OK := (zp[0] <= z) and (z <= zp[L-1]); while not OK do begin Writeln(zp[0]:5:2,' <= z <= ',zp[L-1]:5:2); Write('z := ') ; Readln(z); OK := (zp[0] <= z) and (z <= zp[L-1]); end; end; function trilineair(x,y,z : double; i,j,k : integer) : double; { Trilinear Interpolation } var P,Q,R,f : double; begin P := (x - xp[i-1])/(xp[i] - xp[i-1]); Q := (y - yp[j-1])/(yp[j] - yp[j-1]); R := (z - zp[k-1])/(zp[k] - zp[k-1]); f := (1 - P)*(1 - Q)*(1 - R)*fp[i-1,j-1,k-1] + ( P)*(1 - Q)*(1 - R)*fp[i ,j-1,k-1] + (1 - P)*( Q)*(1 - R)*fp[i-1,j ,k-1] + ( P)*( Q)*(1 - R)*fp[i ,j ,k-1] + (1 - P)*(1 - Q)*( R)*fp[i-1,j-1,k ] + ( P)*(1 - Q)*( R)*fp[i ,j-1,k ] + (1 - P)*( Q)*( R)*fp[i-1,j ,k ] + ( P)*( Q)*( R)*fp[i ,j ,k ]; trilineair := f; end; END. 1234567890123456789012345678901234567890123456789012345678901234567890 program interpol; { Help with Linear programming problem } Uses Speciaal, Generaal; procedure hoofd; { Main } var x,y,z,f : double; i,j,k : integer; begin inlezen(false); Write('xp = '); for k := 0 to Length(xp)-1 do Write(xp[k]:6:2); Writeln; Write('yp = '); for k := 0 to Length(yp)-1 do Write(yp[k]:6:2); Writeln; Write('zp = '); for k := 0 to Length(zp)-1 do Write(zp[k]:6:2); Writeln; Writeln; opvragen(x,y,z); binnen(x,y,z,i,j,k); f := trilineair(x,y,z,i,j,k); Writeln('f(x,y,z) = ',f:6:2); end; begin hoofd; end. 1234567890123456789012345678901234567890123456789012345678901234567890 Han de Bruijn