testbench3.tcl
This calls the shell sh who then runs wish with the file itself.
#!/bin/sh
# WishFix \
exec wish "$0" ${1+"$@"}
#
#
#
Regular package for simulation
package require spice
Here the important line is source differentiate.tcl that contains the optimization library
source differentiate.tcl
Generates a temperature vector
proc temperatures_calc {temp_inf temp_sup points} {
set tstep [ expr " ( $temp_sup - $temp_inf ) / $points " ]
set t $temp_inf
set temperatures ""
for { set i 0 } { $i < $points } { incr i } {
set t [ expr { $t + $tstep } ]
set temperatures "$temperatures $t"
}
return $temperatures }
generates thermistor resistivity as a vector, typically run: thermistance_calc res B [ temperatures_calc temp_inf temp_sup points ]
proc thermistance_calc { res B points } {
set tzero 273.15
set tref 25
set thermistance ""
foreach t $points {
set res_temp [expr " $res *
+ exp ( $B * ( 1 / ($tzero + $t) -
+ 1 / ( $tzero + $tref ) ) ) " ]
set thermistance "$thermistance $res_temp"
}
return $thermistance }
generates the expected floating value as a vector, typically run: tref_calc res B [ temperatures_calc temp_inf temp_sup points ]
proc tref_calc { points } {
set tref ""
foreach t $points {
set tref "$tref[expr "6*(2.275-0.005*($t-20))-9"]"
}
return $tref }
In the optimization algorithm, this function computes the effective floating voltage at the given temperature.