The answer below is a combination of the first answer with a cross-check from Wikipedia (for the obliquity of the ecliptic plane specifically) and here (the formula for ecliptic longitude of the Sun in the first answer uses <PHONE_NUMBER> to multiply sin(2 * g * pi) in the final term instead of 0.020, so I used the factor below, but I am not sure which is correct). Also, the unit vector's direction does not give the distance, so a complete answer needs to scale the unit vector as follows:
First, calculate the Julian offset from J2000 as a decimal number of days d. Then, do the following steps, in order:
1. Calculate parameters
2. Calculate unit directional vector
3. Calculate distance to sun and scale the unit vector
NOTE: All trigonometric function calls (sine, cosine) used below are the versions which accept radians, not degrees! Almost all of the literature in this field uses degrees rather than radians because they are more intuitive for readers of the publications. Also, the reason for dividing by 36525 is to obtain a decimal number of centuries, given that the Julian year is 365.25 days exactly.
1. 371
Calculate parameters
L = <PHONE_NUMBER> + [(36000.77005361 / 36525) * d] a.k.a. mean longitude, in degrees
g = <PHONE_NUMBER> + ([35999.<PHONE_NUMBER>] * d) a.k.a. mean anomaly, in degrees
p = L + <PHONE_NUMBER> * sin(g * pi / 180)] + <PHONE_NUMBER> * sin(2*g * pi / 180)] a.k.a. ecliptic longitude lambda, in degrees
q = 23.43929 - ((46.8093/3600) * (d / 36525)) a.k.a. obliquity of ecliptic plane epsilon, in degrees
2. Calculate unit directional vector in ECI coordinates
u_x = cos(p * pi / 180)
u_y = cos(q * pi / 180) * sin(p * pi / 180)
u_v = sin(q * pi / 180) * sin(p * pi / 180)
3. Calculate distance to sun and scale the unit vector
a = 1.000140612 - [0.016708617 * cos(g * pi / 180)] - [0.000139589 * cos(2 * g * pi / 180)] a.k.a distance from Earth's center to Sun's center in astronomical units (AU)
m = a * 149597870700 a.k.a. center-to-center distance from Earth to Sun in meters
v = m * u_v (or a * u_v) is distance to sun in meters (or in AU) 371