Hello I would like to solve following system of equation:
W1 = Lbc Cos[\[Alpha]1] - Lae + Lde Cos[\[Alpha]3] +
Lcd Sin[\[Alpha]3];
W2 = Lab + Lbc Sin[\[Alpha]1] + Lde Sin[\[Alpha]3] -
Lcd Cos[\[Alpha]3];
SOL = NSolve[{W1 == 0, W2 == 0}, {\[Alpha]3, Lcd}]
Parameters are: Lab = 0.1; Lbc = 0.1; Lae = 0.13; Lde = 0.015;
[Alpha]1 is an input parameter
I get:
NSolve::ifun: Inverse functions are being used by NSolve, so some solutions may not be found; use Reduce for complete solution information.
and very long solution
Do you have any suggestions?
Hi Mateusz,
It is better to work with exact numbers
sol = Solve[{Rationalize@W1 == 0, Rationalize@W2 == 0}, {\[Alpha]3, Lcd}]
Yes, the solution is “long”, but can be verified as correct
W1 /. sol[[1]] /. C[1] -> 0 // Simplify
(* 0 *)
W2 /. sol[[1]] /. C[1] -> 0 // Simplify
(* 0 *)
Similarly for sol[[2]]
hdolhaine
(Hans Dolhaine)
3
What about this? Having c3 you can calculate alpha3.
w1a = W1 /. {Cos[\[Alpha]1] -> c1, Cos[\[Alpha]3] -> c3, Sin[\[Alpha]3] -> Sqrt[1 - c3^2]}
w2a = W2 /. {Sin[\[Alpha]1] -> s1, Sin[\[Alpha]3] -> Sqrt[1 - c3^2], Cos[\[Alpha]3] -> c3}
sol = Solve[{w1a == 0, w2a == 0}, {Lcd, c3}]
sol // Length
sol /. {Lab -> .1, Lbc -> .1, Lae -> .13, Lde -> .015,
s1 -> Sin[\[Alpha]1], c1 -> Cos[\[Alpha]1]} /. \[Alpha]1 -> .237
Maybe I made a mistake but after substitution I do not get 0
Those results are zero within floating point precision.
Hi Mateusz,
No, it was my mistake, should be
Rationalize@W1 /. sol[[1]] /. C[1] -> 0 // Simplify
Much better would be to Rationalize W1 and W2 first
W1 = Rationalize[Lbc Cos[\[Alpha]1] - Lae + Lde Cos[\[Alpha]3] + Lcd Sin[\[Alpha]3]];
W2 = Rationalize[Lab + Lbc Sin[\[Alpha]1] + Lde Sin[\[Alpha]3] - Lcd Cos[\[Alpha]3]];
sol = Solve[{W1 == 0, W2 == 0}, {\[Alpha]3, Lcd}];
(W1 /. sol[[1]] /. C[1] -> 0 // Simplify) ==
(W2 /. sol[[1]] /. C[1] -> 0 // Simplify) ==
(W1 /. sol[[2]] /. C[1] -> 0 // Simplify) ==
(W2 /. sol[[2]] /. C[1] -> 0 // Simplify) == 0
(* True *)
Or to Rationalize the constants first, then there is no need to Rationalize W1 and W2
Lab = Rationalize@0.1; Lbc = Rationalize@0.1; Lae = Rationalize@0.13; Lde = Rationalize@0.015;
Rohit,
Yes to your final sentence. Floating point input led to floating point output.
hdolhaine
(Hans Dolhaine)
8
At least numerically the solutions are if not equal, but almost equal. The negative values of alpha1 are missing, here for alpha1 = .237:
w1a = W1 /. {Cos[\[Alpha]1] -> c1, Cos[\[Alpha]3] -> c3, Sin[\[Alpha]3] -> Sqrt[1 - c3^2]};
w2a = W2 /. {Sin[\[Alpha]1] -> s1, Sin[\[Alpha]3] -> Sqrt[1 - c3^2], Cos[\[Alpha]3] -> c3};
sol = Solve[{w1a == 0, w2a == 0}, {Lcd, c3}];
sol // Length
sol /. {Lab -> .1, Lbc -> .1, Lae -> .13, Lde -> .015, s1 -> Sin[\[Alpha]1], c1 -> Cos[\[Alpha]1]} /. \[Alpha]1 -> .237 /. (c3 -> x_) -> \[Alpha]1 -> ArcCos[x]