Posted to tcl by arjen at Thu Dec 09 14:55:22 GMT 2021view raw
- # temperature.tcl --
- # Simulate a temperature series
- #
- proc temp {alpha mean min max number} {
- set result {}
- set mean [expr {(1.0 - $alpha) * $mean}]
- set range [expr {($max - $min) / 4.0}]
- set t1 [expr {$mean + $range * (rand() - 0.5)}]
- set t1 [expr {min($max,max($min,$t1))}]
- for {set i 0} {$i < $number} {incr i} {
- set t2 [expr {$alpha * $t1 + $mean + $range * (rand() - 0.5)}]
- set t2 [expr {min($max,max($min,$t2))}]
- lappend result $t2
- set t1 $t2
- }
- return $result
- }
- package require Plotchart
- pack [canvas .c -width 600 -height 600]
- set p [::Plotchart::createXYPlot .c {0 100 20} {-10 10 5}]
- incr x 0
- foreach t [temp 0.5 4.0 -8.0 8.0 100] {
- $p plot data $x $t
- incr x
- }