i am working on plotting cubic interpolating curve graph in java, and encountered problem in finding the y with give at some dx value.
what i am doing is :
suppose i have 4 set of co ordinates
$(x_1,y_1)\\ (x_2,y_2)\\ (x_3,y_3)\\ (x_4,y_4)$
and created the 4 cubic equation from 4 coordinates
$y_1 = a \cdot x_1^3 + b \cdot x_1^2 + c \cdot x_1 + d\\ y_2 = a \cdot x_2^3 + b \cdot x_2^2 + c \cdot x_2 + d\\ y_3 = a \cdot x_3^3 + b \cdot x_3^2 + c \cdot x_3 + d\\ y4 = a \cdot x_4^3 + b \cdot x_4^2 + c \cdot x_4 + d$
i know the values of $x_1,x_2,x_3,x_4,y_1,y_2,y_3,y_4$ i want to find coefficients $a,b,c,d$ so that i can find the $y$ at any given $x$ with cubic equation.
i don't know i am doing right or wrong. please help and correct if i am wrong i case.
What you have will work, creating a system of 4 linear equations, and is not too hard to solve in the specific case, but becomes more difficult in the abstract cases to solve.
Here is an algorithm that will work for $n$ pairs of coordinates (producing a degree $n-1$ polynomial)
$\begin {array}\\ x_1 &y_1\\ &&F_{2,1}=\frac {y_2-y_1}{x_2 - x_1}\\ x_2 &y_2&&&F_{3,1} = \frac {F_{3,2} - F_{2,1}}{x_3-x_1}\\ &&F_{3,2}=\frac {y_3-y_2}{x_3 - x_2}&&&F_{4,1} = \frac {F_{4,2} - F_{3,1}}{x_4-x_1}\\ x_3 &y_3&&&F_{4,2} = \frac {F_{4,3} - F_{3,2}}{x_4-x_2}\\ &&F_{4,3}=\frac {y_4-y_3}{x_4 - x_3}\\ x_4 &y_4 \end {array} $
$y = y_1 + F_{2,1}(x-x_1) + F_{3,1}(x-x_1)(x-x_2)+ F_{4,1}(x-x_1)(x-x_2)(x-x_3)$