MPU 9250, YAW wrong

Hello everyone. I’m trying to calculate the 3 angles of ROLL, PITCH and YAW to stabilize a drone.
Currently I can get: ROOL and PITCH with the following formulas:

pitch = 180 * atan (accelerationX / sqrt (accelerationY * accelerationY + accelerationZ * accelerationZ)) / M_PI;
roll = 180 * atan (accelerationY / sqrt (accelerationX * accelerationX + accelerationZ * accelerationZ)) / M_PI;

but if I use this expression, with the values of the magnometer, for the Yaw are incorrect values:
Yaw = atan2 ((-YY * cos (Roll) + MyZ * sin (Roll)), (MyX * cos (Pitch) + MyY * sin (Pitch) * sin (Roll) + MyZ * sin (Pitch) * cos ( Roll)))

I am attaching my code, you know the right expression to get the angle of YAW ?? or some solution for my problem
thank you

MPU9250_01.ino (3.16 KB)

I'd love to help but I don't really see how calculating yaw is an Arduino problem. If there's a problem with the math, check some books on avionics, I can give you some titles. Otherwise, post your results complete with the compiler-generated error messages and see what happens.

If your code works, then its a problem with the formula and this isn't necessarily the place to look for an answer, unless you get lucky.

Do not cross post.

Use a matrix, and look at this