I need help with NSolve.. below I explain the maths of what I am doing so the question becomes clear..
I have two points, P1 and P2, defined in Euler angles relative to the origin of the spherical coordinates frame:
P1[alpha_,beta_,gamma_]:={-0.5207928328826381` Cos[alpha] Sin[beta] -
0.7566899220728581` (Cos[beta] Cos[alpha] Cos[gamma] - Sin[alpha] Sin[gamma]), -0.5207928328826381` Sin[beta] Sin[alpha] - 0.7566899220728581` (Cos[beta] Cos[gamma] Sin[alpha] +Cos[alpha] Sin[gamma]), -0.5207928328826381`Cos[beta] + 0.7566899220728581` Cos[gamma] Sin[beta]};
P2[alpha_,beta_,gamma_]:={-0.5207928328826381` Cos[alpha] Sin[beta] +
0.7566899220728581` (Cos[beta] Cos[alpha] Cos[gamma] - Sin[alpha] Sin[gamma]), -0.5207928328826381` Sin[beta] Sin[alpha] + 0.7566899220728581` (Cos[beta] Cos[gamma] Sin[alpha] +Cos[alpha] Sin[gamma]), -0.5207928328826381`Cos[beta] - 0.7566899220728581` Cos[gamma] Sin[beta]};
I want to shift these two points to a general position, so I define the spherical coordinates of a centre as
R[r_,theta_,phi_]:=r {Sin[theta] Cos[phi], Sin[theta] Sin[phi], Cos[theta]};
However I change the Euler angles, I want to keep the radial distance of the R fixed at 0.0949009, in other words, I always have
R[0.0949009,theta,phi]
and at the same time I want the radial distances of the two points, P1 and P2 equal 0.753964 at all values of Euler angles, so I solve for theta and phi values that satisfy this condition
functoSolve[alpha_, beta_, gamma_] := Module[{a1, a2}, a1 = Chop[NSolve[{(P1[alpha, beta, gamma]+ R[0.0949009,theta,phi]).(P1[alpha, beta, gamma]+ R[0.0949009,theta,phi]) ==0.753964, (P2[alpha, beta, gamma]+ R[0.0949009,theta,phi]).(P2[alpha, beta, gamma]+ R[0.0949009,theta,phi]) ==0.753964}, {theta,phi}], 10^-7]; a2 = Union[a1, SameTest -> (Abs[ (theta /. #1) - (theta /. #2)] < 10^-6 && Abs[(phi. #1) - (phi /. #2)] < 10^-6 &)]; Chop[P[0.0949009,theta,phi] /. a2[[1]], 10^-7]]
where a2 picks the first solution since NSolve returns all possible solution. So the functoSolve is the function I need to use many times to find theta and gamma for any {alpha,beta,gamma} combination. It works for when I put {alpha, beta, gamma}={0,0,0}. However, for any other combination, such as {10 Degree, 4 Degree, 0},NSolve fails to find the solution and returns the error messages
NSolve::ifun: Inverse functions are being used by NSolve, so some solutions may not be found; use Reduce for complete solution information. >>
NSolve::svars: Equations may not give solutions for all "solve" variables. >>
I cannot understand why Mathematica complains (!!) the maths is OK and the problem is simple enough. I do not need a high precision solution but I need a solution.
I really need help fix this problem.
Thanks,
eft