You did not ask for help in the physics so it does not belong in physics.
you did not ask for help with the math, so it does not belong in math.
you asked for code. that is programming.
I think you need math help and are asking the wrong place. go have a chat with your prof. We do not do homework for you, we help. Asking for code is not what we provide.