I have 6 equations
0.344027==0.5 (a+b)-0.5 (a-b) Cos[2 (-1.3439-0.0174533 c)]
0.679511==0.5 (a+b)-0.5 (a-b) Cos[2 (0.20944 -0.0174533 c)]
0.436543==0.5 (a+b)-0.5 (a-b) Cos[2 (-0.733038-0.0174533 c)]
0.324024==0.5 (a+b)-0.5 (a-b) Cos[2 (1.18682 -0.0174533 c)]
0.304968==0.5 (a+b)-0.5 (a-b) Cos[2 (-1.5708-0.0174533 c)]
0.676049==0.5 (a+b)-0.5 (a-b) Cos[2 (-0.174533-0.0174533 c)]
I could pick 3 equations from the list and got exact answers. However, I want my variables (a,b,c) to have values such that the right hand sides of all 6 equations approach the left hand side as much as possible. I'm not really sure what I can use in this case to resolve this.
Edit: I used Kuba's method to solve my problem. However, using FindFit (per belisarius' helpful suggestion) also gave me the same result. This works because all 6 equations have a pair of x and y that could be fitted through multivariable FindFit-- though if I were to be given random equations with a,b,c, NMinimize might be the only method to find them.
FindFit example in MMA's documentation
Using FindFit to my example
Original equations:
0.344027==0.5 (a+b)-0.5 (a-b) Cos[2 (-1.3439-0.0174533 c)]
0.679511==0.5 (a+b)-0.5 (a-b) Cos[2 (0.20944 -0.0174533 c)]
0.436543==0.5 (a+b)-0.5 (a-b) Cos[2 (-0.733038-0.0174533 c)]
0.324024==0.5 (a+b)-0.5 (a-b) Cos[2 (1.18682 -0.0174533 c)]
0.304968==0.5 (a+b)-0.5 (a-b) Cos[2 (-1.5708-0.0174533 c)]
0.676049==0.5 (a+b)-0.5 (a-b) Cos[2 (-0.174533-0.0174533 c)]
yData = {0.344027, 0.679511, 0.436543, 0.324024, 0.304968, 0.676049};
xData = {-1.3439, 0.20944, -0.733038, 1.18682, -1.5708, -0.174533};
data = {xData, yData, Table[0, {6}]} // Transpose;
model = y - (0.5 (a + b) - 0.5 (a - b) Cos[2 (x - 0.0174533 c)]);
fit = FindFit[data, model, {a, b, c}, {x, y}]
model /. fit /. {y -> yData, x -> xData}
Show[Plot3D[model /. fit, {x, -2, 2}, {y, 0, 1},
AxesLabel -> Automatic,
MeshShading -> {{None, None}, {None, None}}],
ListPointPlot3D[data, PlotStyle -> Directive[PointSize[Medium], Red]],
ListPlot3D[data, VertexColors -> Hue]]
Answer
ClearAll[a, b, c]
NMinimize[
#.# &[Subtract @@@ {
0.344027 == 0.5 (a + b) - 0.5 (a - b) Cos[2 (-1.3439 - 0.0174533 c)],
0.679511 == 0.5 (a + b) - 0.5 (a - b) Cos[2 (0.20944 - 0.0174533 c)],
0.436543 == 0.5 (a + b) - 0.5 (a - b) Cos[2 (-0.733038 - 0.0174533 c)],
0.324024 == 0.5 (a + b) - 0.5 (a - b) Cos[2 (1.18682 - 0.0174533 c)],
0.304968 == 0.5 (a + b) - 0.5 (a - b) Cos[2 (-1.5708 - 0.0174533 c)],
0.676049 == 0.5 (a + b) - 0.5 (a - b) Cos[2 (-0.174533 - 0.0174533 c)]
}], {a, b, c}]
{0.0059057, {a -> 0.291325, b -> 0.677473, c -> 3.2186}}
Comments
Post a Comment