(*This programme is written to solve the 1-D (FORWARD) gravity problem*)
(*Input Part*)
m={{1,1,1},{4,2,1},{9,3,1},{16,4,1},{25,5,1}};(*This is the matrix of coefficients*)
xx={a,b,c};(*This is the matrix of variables*)
g={1.39,2.21,3.21,4.39,5.81};(*This is the matrix of gravity readings*)
(*Calculations Part*)
sol=Inverse[Transpose[m].m].Transpose[m].g;(*Solving the equations for the Predetermined case*)
grav[x_]=sol[[1]]*(x^2)+sol[[2]]*x+sol[[3]];(*The equation of gravity anomaly with the constants*)
(*Output Part*)
Print["The values of the variables a, b, and c are ",sol[[1]],", ",sol[[2]],", ","and ",sol[[3]]," respectively."]
Print["The gravity at x=2.5 m is ",grav[2.5]," m/(s^2)"]
Print["The gravity at x=4.5 m is ",grav[4.5]," m/(s^2)"]

Clear[m,xx,a,b,c,d,g,sol,grav]
(*This programme is written to solve the 2-D (Forward) gravity problem*)
(*Input Part*)
m={{0,0,0,1},{0,1,1,1},{1,0,0,1},{1,1,1,1},{4,0,0,1},{0,4,2,1},{4,1,1,1},{1,4,2,1}};(*This is the matrix of coefficients*)
xx={a,b,c,d};(*This is the matrix of constants*)
g={0.95,1.19,1.09,1.21,1.39,1.81,1.40,1.72};(*This is the matrix of gravity readings*)
(*Calculations Part*)
sol=Inverse[Transpose[m].m].Transpose[m].g;(*Solving the equations for the Predetermined case*)
grav[x_,y_]=sol[[1]]*(x^2)+sol[[2]]*(y^2)+sol[[3]]*y+sol[[4]];(*The equation of gravity anomaly with the constants*)
(*Output Part*)
Print["The values of the variables a, b, c, and d are ",sol[[1]],", ",sol[[2]],", ",sol[[3]],","," and ",sol[[4]]," respectively."]
Print["The gravity at x=1.5 m, y=1.25 m is ",grav[1.5,1.25]," m/(s^2)"]
Print["The gravity at x=0.25 m, y=1.75 m is ",grav[0.25,1.75]," m/(s^2)"]