function f_g = f_g(l, b, s, theta)

% Define the variables (example values provided, replace as necessary)
Sx = s(1); Sy = s(2); Sz = s(3);
Bx = b(1); By = b(2); Bz = b(3);
Vx = l(1); Vy = l(2); Vz = l(3);
theta_xy = theta(1); theta_xz = theta(2); theta_yz = theta(3);

g_x = (Vx - Bx)/Sx;
g_y = (1/(Sy*cos(theta_xy)))*(Vy - By - ((Vx - Bx)/Sx)*Sy*sin(theta_xy));
g_z = (1/(cos(theta_yz)*cos(theta_xz))) * (((Vz-Bz)/Sz) - ((Vx-Bx)/Sx)*sin(theta_xz) - ((sin(theta_yz)*cos(theta_xz))/(Sy*cos(theta_xy))) * (Vy - By - ((Vx-Bx)/Sx)*Sy*sin(theta_xy)));

f_g = g_x^2 + g_y^2 + g_z^2 - 9.81^2;

end