Version 29 of Example Linear Interpolation Calculator

Updated 2017-11-13 22:36:09 by gold

Example Linear Interpolation Calculator

This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please sign your user-name with the same courtesy that I will give you. Thanks,gold

Introduction


gold 17Jul2010, Here is some starter code for Example Linear Interpolation Calculator written in eTCL. This eTCL script calls on console show, which can act funny on other TCL interpreters.


For the report button, the linear interpolation function takes two known points on a line and solves for an intermediate point. The points are xx1,yy1 xx2,yy2 and xx3,?yy3? The input order of the five items is xx1 yy1 xx2 yy2 xx3 and solving for ?yy3?. The interpolation function loaded as proc pol. User should be able to write pol 50. 1000. 200. 1200. 150. and save answer (1133.3) on console.


Screenshots Section

http://farm5.static.flickr.com/4118/4803438156_b62e060e8b.jpg


Comments Section

Please place any comments here, Thanks.

gold Changes.

The easiest way to do interpolation of _any_ kind of transfer is via blt vector. Describe your transfer via a pair of x/y vectors and use the blt_spline function to interpolate to a pair of single item vectors sx/sy see interpolation via blt::vector. UK


References*

appendix TCL programs

Pretty Print VERSION

# pretty print version from autoindent and ased  
# written on Windowws XP on eTCL
# working under TCL version 8.5.6 and eTCL 1.0.1
# gold on TCL WIKI , 17Jul2010
package require Tk
frame .frame -relief flat -bg aquamarine4
pack .frame -side top -fill y -anchor center

set names {{} x1: y1: {x3:} {y3:} {x2:} {answer:} possible:}
foreach i {1 2 3 4 5 6 } {
    label .frame.label$i -text [lindex $names $i] -anchor e
    entry .frame.entry$i -width 35 -textvariable side$i
    grid .frame.label$i .frame.entry$i -sticky ew -pady 2 -padx 1
}

proc about {} {
    set msg "Calculator for linear interpolation.\nfrom TCL WIKI,\nwritten on eTCL "
    tk_messageBox -title "About" -message $msg
}

proc pi {} {expr acos(-1)}

proc interlinear { xx1 yy1 xx3 yy3 xx2 } {
    return [expr { ((($xx2-$xx1)*($yy3-$yy1))/($xx3-$xx1))+ $yy1 } ] }

proc pol { xx1 yy1 xx3 yy3 xx2 } {
    return [expr { ((($xx2-$xx1)*($yy3-$yy1))/($xx3-$xx1))+ $yy1 } ] }

proc calculate {     } {
    global answer2
    global side1 side2 side3 side4 side5 side6
    set answer2 [ interlinear  $side1 $side2 $side3 $side4 $side5  ]
    set side6 $answer2
    set pi5 [pi]
    if {$answer2 >= $pi5} { set error5   [expr {100.*$answer2/$pi5-100.}]   }
    if {$answer2 <= $pi5} { set error5   [expr {100.*$pi5/$answer2-100.}]   }
    #$x insert 1.0 " % error $error5 "
    #$t insert 1.0 " % error  $error5 "
}

proc fillup {aa bb cc dd ee ff} {
    .frame.entry1 insert 0 "$aa"
    .frame.entry2 insert 0 "$bb"
    .frame.entry3 insert 0 "$cc"
    .frame.entry4 insert 0 "$dd"
    .frame.entry5 insert 0 "$ee"
    .frame.entry6 insert 0 "$ff"
}

proc clearx {} {
    foreach i {1 2 3 4 5 6} {
        .frame.entry$i delete 0 end
    }
}

proc reportx {} {
    console show
    puts "
    The interpolation function takes
    two know points on a line and
    solves for an intermediate point.
    The points are xx1,yy1   xx2,yy2 and xx3,?yy3?
    The input order of the five items
    is xx1 yy1 xx2 yy2 xx3
    and solving for ?yy3?.
    The interpolation function loaded as
    proc pol. User should be able to write
    pol 50. 1000. 200. 1200.  150.
    and save answer (1133.3)  on console."
}

frame .buttons -bg aquamarine4

::ttk::button .calculator -text "Solve" -command calculate
::ttk::button .test2 -text "Testcase1" -command { clearx;fillup 10.  100.  60.  120.   50.  116 }
::ttk::button .test3 -text "Testcase2" -command { clearx;fillup 50.  1000. 200. 1200.  150. 1133 }
::ttk::button .test4 -text "Testcase3" -command { clearx;fillup 200. 1000. 300. 1500.  250. 1250}
::ttk::button .clearallx -text clear -command clearx
::ttk::button .about -text about -command about
::ttk::button .cons -text report -command reportx
::ttk::button .exit -text exit -command exit

pack .calculator  -in .buttons -side top -padx 10 -pady 5
pack .clearallx .cons .about .exit .test4 .test3 .test2 -side bottom -in .buttons
grid .frame .buttons -sticky ns -pady {0 10}
. configure -background aquamarine4 -highlightcolor brown -relief raised -border 30
wm title . "Linear Interpolation Calculator"


gold This page is copyrighted under the TCL/TK license terms, this license .