Posted to tcl by arjen at Thu Dec 09 14:55:22 GMT 2021view raw

  1. # temperature.tcl --
  2. # Simulate a temperature series
  3. #
  4. proc temp {alpha mean min max number} {
  5. set result {}
  6.  
  7. set mean [expr {(1.0 - $alpha) * $mean}]
  8. set range [expr {($max - $min) / 4.0}]
  9. set t1 [expr {$mean + $range * (rand() - 0.5)}]
  10. set t1 [expr {min($max,max($min,$t1))}]
  11. for {set i 0} {$i < $number} {incr i} {
  12. set t2 [expr {$alpha * $t1 + $mean + $range * (rand() - 0.5)}]
  13. set t2 [expr {min($max,max($min,$t2))}]
  14.  
  15. lappend result $t2
  16. set t1 $t2
  17. }
  18.  
  19. return $result
  20. }
  21.  
  22. package require Plotchart
  23. pack [canvas .c -width 600 -height 600]
  24. set p [::Plotchart::createXYPlot .c {0 100 20} {-10 10 5}]
  25.  
  26. incr x 0
  27. foreach t [temp 0.5 4.0 -8.0 8.0 100] {
  28. $p plot data $x $t
  29. incr x
  30. }