0

I have 3 equations

$y_1=ax_1^2+bx_1+c$,

$y_2=ax_2^2+bx_2+c$,

$y_3=ax_3^2+bx_3+c$

i.e. 3 pairs of values $x_1$,$y_1$, $x_2$,$y_2$ and $x_3$,$y_3$ and I need to fit the curve. I found lots of code for $n$ pairs using matrices but really just have this simple case of 3

I need $a,b,c$ in terms of the paired values.

There must be a simple equation?

geoff123
  • 101
  • 1
    What you have is a system of linear equations on $a$, $b$, $c$. Just solve it using elimination or any other technique you know. – lhf Nov 05 '14 at 11:05
  • I understand I have to solve the 3 linear simultanous equations but I dont know how to do that. I need a,b and c in terms of x1,y1,x2,y2,x3,y3 so I can do for generic data (in a mobile phone automatically) – geoff123 Nov 05 '14 at 11:07
  • See http://en.wikipedia.org/wiki/Lagrange_polynomial. – lhf Nov 05 '14 at 11:09
  • So you are trying to get us to help you cheat on a test? – Tim Seguine Nov 05 '14 at 11:13
  • 1
    not trying to cheat on a test. i have a temperature sensor based on a mobile phone which needs calibrating with 3 values of temp and rms_voltage because the actual curve is a nice polynomial. i'm too old for tests ;) – geoff123 Nov 05 '14 at 11:17
  • You could try Cramer's Rule. – Gerry Myerson Nov 05 '14 at 11:33
  • Thanks lhf - i used lagrange – geoff123 Nov 05 '14 at 11:42
  • r1=1.0 r2=2.0 r3=3.0 t1=1.0 t2=8.0 t3=27.0

    d1=(r1-r2)(r1-r3) d2=(r2-r1)(r2-r3) d3=(r3-r1)*(r3-r2)

    a=t1/d1+t2/d2+t3/d3 b=t1(-x2-x3)/d1 + t2(-x1-x3)/d2 + t3(-x1-x2)/d3 c=t1(-x2(-x3))/d1 + t2(-x1(-x3))/d2 + t3(-x1*(-x2))/d3

    print,a print,b print,c

    is the answer if i did my algebra right!

    – geoff123 Nov 05 '14 at 11:56

1 Answers1

0

If this is just what you need, eliminate variables one after each other. You will be left with one linear equation to solve for $c$ $$c=\frac{x_3 (y_1-y_2)+x_1 (y_2-y_3)+x_2 (y_3-y_1)}{(x_1-x_2) (x_1-x_3) (x_2-x_3)}$$ $$b=\frac{y_1-y_2}{x_1-x_2}-c (x_1+x_2)$$ $$a=y_1-bx_1-c x_1^2$$