**Example Linear Interpolation Calculator** ---- This page is under development. Comments are welcome, but please load any comments in the comments section at the middle of the page. Thanks,[gold] ---- ---- 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. The linear 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. ---- ---- ---- ---- ---- ---- ---- **Screenshots Section** ---- **Comments Section** Please place any comments here, Thanks. [gold] Changes. ====== ---- **References*** http://wiki.tcl.tk/11339 Straightforward interpolation methods http://www.eng.fsu.edu/~dommelen/courses/eml3100/aids/intpol/index.html http://faculty.ksu.edu.sa/11843/interpolation/Linear-interpolation12-14-06.pdf www.stat.uiowa.edu/ftp/atkinson/ENA_Materials/Overheads/sec_4-2.pdf http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/interpolation/ **appendix TCL programs** ***FIRST VERSION*** proc positionWindow w { wm geometry $w +300+300 } set font {Helvetica 18} 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. from TCL WIKI, written 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 colorwarning global colorback global answer2 answer3 global side1 side2 side3 side4 side5 side6 set answer2 "" 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 bind . {wm title . "Linear Interpolation Calculator"} ====== ****SECOND VERSION WITH ADDED HACKS *** ====== #start of deck#!/bin/sh #end of deck #end of deck #end of deck #end of deck #end of deck #end of deck ****Version with added hacks **** proc positionWindow w { wm geometry $w +300+300 } set font {Helvetica 18} set colorgrd seashell4 set colorback bisque set colorwarning tomato1 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. from TCL WIKI" 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 calculate { } { global colorwarning global colorback global answer2 answer3 global side1 side2 side3 side4 side5 side6 set answer2 "" 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 } } 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 .exit -text exit -command {exit} pack .calculator -in .buttons -side top -padx 10 -pady 5 pack .clearallx .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 bind . {wm title . "Linear Interpolation Calculator"} #start of deck #start of deck #start of deck #end of deck #end of deck #end of deck #end of deck #end of deck #end of deck #end of deck ====== ---- <> Toys | Example | Math|Function | Numerical Analysis|Engineering <>Enter Category Here