I've been making a Mathematica script whereby a spacecraft is transferred from Earth to Mars using a Hohmann interplanetary transfer by means of a patched conic approximation.
As far as I can tell all of the equations and numbers should be correct, yet when running the code the spacecraft doesn't make it to Mars. Without getting into any detail of the code (that will have to be for the Mathematica SX forums), I wanted to ask how accurate the patched conic approximation really is. If all of the numbers are correct should I be able to run the code and the spacecraft will hit Mars, or is it supposed to be used to find a rough trajectory to another planet? I understand the inherent inaccuracies with the approximation since it considers everything in terms of individual 2-body problems, and so thought I might be a little too hopeful when I thought it would get me to Mars.
EDIT: Okay, I think my initial post used an incorrect angle for applying the delta-v impulse which I have since fixed (I think!). I made a second program that looked at just the Earth and spacecraft upon departure to confirm whether my angle was correct and this is what I got (the spacecraft doesn't actually pass through the green circle (Earth). The green circle is just the position of Earth at the start of the simulation):
As you can see, the spacecraft's escape velocity is parallel to the Earth's velocity which is a good start. I got the correct angle by finding the angle of the Earth's velocity vector using phi = arctan(v_y/v_x), the "impulse angle" (not too sure what to call it) by using beta = arccos(1/e) and then using theta = phi + beta + pi when finding the x- and y-components for delta-v = v_p - v_c (where v_x and v_y are the x- and y-components of the Earth's velocity respectively, e is the escape hyperbola's eccentricity and v_p and v_c are the spacecraft's periapse speed and circular orbit speed about Earth respectively).
Unfortunately, when running the full program again in the Sun's frame of reference I found the following:
1) Roughly half-period of spacecraft orbit about Sun
2) Full period of spacecraft orbit about Sun
P.S. The equations I'm using are from Orbital Mechanics for Engineering Students by Howard Curtis.
UPDATE: Solution to Earth-Mars interplanetary transfer using Lambert solver (some much needed coding help was given my the Mathematica SX forums).