News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

linear interpolation

Started by RuiLoureiro, April 14, 2012, 07:49:58 PM

Previous topic - Next topic

RuiLoureiro

            To define a set of points we write something like this:

            point(x1,y1; x2,y2; x3,y3; ...)

            To get the linear interpolation we type

            f(x=a) [ENTER/COMPUTE] and the calculator gives x=a and y=b as solutions
            or
            f(y=b) [ENTER/COMPUTE] and the calculator gives x=a and y=b as solutions.

            Example:
                     point(3,6; 4,8) [COMPUTE]

            and
                     f(x=3.1) [COMPUTE]
           
            The prog calculte the function Y=bX+c based on (3,6) and (4,8)
            and then calculate Y1=b*3.1+c and it should give the result

                            X=3.1
                            Y=Y1

            Do you want to say something about this ?
            Have you any other idea ?
            Thanks

dedndave

it is called the "slope-intercept" form
it is usually written as

Y = mX + b
or
f(X) = mX + b

where m is the slope of the graphed line
and b is the intercept (or Y intercept, the value of Y where the graphed line crosses the origin)

you can solve for m and b with any 2 points via simultaneus equations

RuiLoureiro

#2
Dave,
Quote
"Undefined"
how about interpolate/extrapolate   
i.e., when they enter a linear equation, it waits for them to enter an X or Y to plot the point

...then add a BSL function with interpolate/extrapolate
            This was your idea or suggestion.
            Now the problem is how to integrate it in calculaXX.

            To do a linear interpolation, the first thing to do
            is to define a set of points (x,y). How ?
           
            My suggestion is to create a function

              (a)  point(x1,y1; x2,y2; ...;xn,yn)

            In this way we put that set of points in one table in the memory.

            After this the problem is how to interpolate ?

            My suggestion is to create 2 functions

                        f(x=number)  or f(y=number)

            In this way, in calculaXX, when we type an input like f(x=3.1)

            calculaXX use the table defined by function (a), and execute

            a linear interpolation to get the result y and show the result

                            x=number   y=result

            Did you understand ?
            What about this ?

dedndave

first, a linear equation may be described using only 2 points

(X1, Y1)
(X2, Y2)

if they define a 3rd point and it is not on the same line, then it is not a linear equation

probably the easiest way to solve for "m" (slope) and "b" (intercept) is to solve for "m", first:

m = (Y2 - Y1) / (X2 - X1) = (Y1 - Y2) / (X1 - X2)

the slope is often described as "the rise over the run"
be careful not to execute divide-by-zero   :P
if X1 = X2, it is a line, straight up and down

then, it is easy to solve for "b"

b = Y1 - m * X1 = Y2 - m * X2

once you have "m" and "b", they can enter any X value and get a Y, or enter any Y value and get an X
that handles both interpolation and extrapolation

RuiLoureiro

Dave,
        1. I think you agree with me about the functions

           point(x1,y1; x2,y2; ...;xn,yn), f(x=number)  and f(y=number)

           to execute interpolation using calculaXX;

        2. I think you dont know exactly what is a linear interpolation.
       
           To use a linear interpolation we dont need to have a set
           of points that follow a linear equation y=mx+b.


           We can define any set of points, not 2 points (X1, Y1) and (X2, Y2).
           That set of points can follow a complex function y=f(x), it
           is not important if we want to get an approximation, in this
           case, using one linear equation y=mx+b. Obviously that approximation
           may be good or bad. This is linear interpolation.

        3. Suppose we have the function f(x)=x^2+1. The points (0,1), (1,3), (2,5)
           follow that function.
           
           We can use a linear interpolation to estimate the value of f(0.1)
           In this case we use the points (0,1), (1,3) to get the linear equation
           y=mx+b and we calculate y=m*0.1+b and at the end we say y is an estimate
           of f(0.1).[Obviously we calculate m and b from (0,1), (1,3)]
           
           Obviously it is not a good idea to use that y=mx+b to get an estimate
           of f(3)! The better idea is to use (1,3), (2,5) i think.

           Any doubt ?

dedndave

you are right, of course
you may use linear interpolation for any function
results may vary   :P
the farther apart the 2 points are, the less likely you are to get good results (depends on the function, of course)

what i was thinking about was a simple linear function
the reason i brought it up was - my calculator can do it   :bg
you can enter 2 points and either a Y or X value, and it will give you the X or Y
it will also do average, median, standard deviation - all that stuff

it would be nice if i could plug a function in and get the slope at a given X or Y   :P

RuiLoureiro

Dave,
Quote
the reason i brought it up was - my calculator can do it   
you can enter 2 points and either a Y or X value, and it will give you the X or Y

           Thanks for your idea.
           
           I will try to implement it in the next calcula36.
           
           We define up to 10 points, minimum 2 using

                point(x1,y1; x2,y2; ...; x9,y9; x10,y10)