I would like to find the best fit of two variables for a number of approximate equations, such as:
1x+2y+2=7.04
2x+y+4=7.98
1.5x+1.5y-2=2.53
1.8x+3y-1=6.77
That should come up with a result: x = ~1, y = ~2 (exact value for whatever the best fit is).
I can't find any inspiration in either
I don't expect anyone to do it for me, but perhaps someone could push me in a correct direction?
Thanks in advance, r.
Answer
I think this is what you are after:
NMinimize[
#.# &[Subtract @@@ {
1 x + 2 y + 2 == 7.04,
2 x + y + 4 == 7.98,
1.5 x + 1.5 y - 2 == 2.53,
1.8 x + 3 y - 1 == 6.77
}],
{x, y}]
{0.00360363, {x -> 0.99076, y -> 2.00755}}
Comments
Post a Comment