Find the values of 3 variables that best fit 6 equations [duplicate]

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]]

-

marked as duplicate by Kuba, bobthechemist, Yves Klett, Öskå, Michael E2Jun 18 '14 at 13:54

I think it is a duplicate of Fitting a variable using multiple equations. Tell me what do you think –  Kuba Jun 18 '14 at 11:03

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}}

-
Thank you so much for your help Kuba. I have a question: it seems like you were trying to find the dot product of the list of the (subtraction) equations and minimize it to find the best roots. Is this a standard math practice, and if so does it have a name or is there anywhere I could learn more about it? I'm just a college student so my math skills are not very strong. –  seismatica Jun 21 '14 at 8:06
@seismatica Hi, I'm glad I could help. Before dot product there is subtraction so at the end we are minimizing sum of squared differences, like in standard lsq method but via black box NMinimize :) –  Kuba Jun 21 '14 at 14:23

You may use FindFit

l = {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)]};
l1 = (List@@@l) /. {x1_,x2_} :>Flatten@{Cases[x2,Cos[2 x__] :> (List @@ x /.c :> 1), 2], x1};
ff = FindFit[l1, .5 u - .5 v Cos[2 (x + y c)], {u, v, c}, {x, y}]
Solve[{a + b == u, a - b == v} /. ff, {a, b}]

(*
{u -> 0.968798, v -> -0.386148, c -> 3.2186}
{{a -> 0.291325, b -> 0.677473}}
*)

-
Thank you so much for your help belisarius. I've edited my question with the FindFit method you suggested in a way that feels more intuitive to me. –  seismatica Jun 21 '14 at 12:40
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.30156999826431274, "perplexity": 5166.1428089968795}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2015-35/segments/1440644065330.34/warc/CC-MAIN-20150827025425-00070-ip-10-171-96-226.ec2.internal.warc.gz"}