$result
のproc Inverse2
を1秒ごとにスケジュールして保存しようとしています(別のプロシージャ内で呼び出され、そのプロシージャは1秒間に再スケジュールされます)。 Inverse2手順) 私は{今のxy}で出力を取得し、最新のためにそれに変数を割り当てる2つのインスタンス エラーの原因「浮動小数点例外(コアダンプ)」
x1-> x location at current time (for example at 8.0)
y1-> y location at current time
x2-> x location at (current time+1) (for example at 9.0)
y2-> y location at (current time+1)
をし、さらに計算に使用したい理由です。 以下は試したコードですが、2回繰り返した後にエラーが発生するのは
Floating point exception (core dumped)
です。どこが間違っているの?
コード:
set result {}
proc Inverse2 {m} {
set op [open output.tr w]
global result
global ns
set now [$ns now]
lassign [lindex $m 0 2] x1
lassign [lindex $m 0 3] y1
lassign [lindex $m 0 6] d1
lassign [lindex $m 1 2] x2
lassign [lindex $m 1 3] y2
lassign [lindex $m 1 6] d2
lassign [lindex $m 2 2] x3
lassign [lindex $m 2 3] y3
lassign [lindex $m 2 6] d3
set mt {{? ?} {? ?}}
lset mt 0 0 [expr 2*($x1-$x2)]
lset mt 0 1 [expr 2*($y1-$y2)]
lset mt 1 0 [expr 2*($x1-$x3)]
lset mt 1 1 [expr 2*($y1-$y3)]
set const {{?} {?}}
lset const 0 [expr {(pow($x1,2)+pow($y1,2)-pow($d1,2))-(pow($x2,2)+pow($y2,2)-pow($d2,2))}]
lset const 1 [expr {(pow($x1,2)+pow($y1,2)-pow($d1,2))-(pow($x3,2)+pow($y3,2)-pow($d3,2))}]
#puts $result "$const"
# puts $result "$mt"
set x [expr {double([lindex [Inverse3 $mt] 0 0] * [lindex $const 0]
+ [lindex [Inverse3 $mt] 0 1] * [lindex $const 1])}]
set y [expr {double([lindex [Inverse3 $mt] 1 0] * [lindex $const 0]
+ [lindex [Inverse3 $mt] 1 1] * [lindex $const 1])}]
lappend result "$x $y $now"
puts $result
for {set i 0} {$i< [llength $result]} {incr i} { #for latest two instances
for {set j 1} {$i< [llength $result]} {incr j} {
set X1 [lindex $result $i 0]
set Y1 [lindex $result $i 1]
if {[llength $result] >1} { #to ensure length of list is greater than 1
set X2 [lindex $result $j 0]
set Y2 [lindex $result $j 1]
set v [expr hypot($X2-$X1,$Y2-$Y1)/ ($now-($now-1))]
set theta [expr acos(($X2-$X1)/(hypot($X2-$X1,$Y2-$Y1)))]
set Xp [expr ($X2+($v*$now*cos($theta)))]
set Yp [expr ($Y2+($v*$now*sin($theta)))]
puts "$Xp $Yp"
}
break
}
}
}
はこの{500.1 450 8.0} {378.1 478 9.0}のように見えるresult' 2回の反復 '$後this.egなどの最新の2組のために、すなわち、' $のresult'出力に変数を割り当てますだから、x1> [lindex $ result 0 0]&y1> [lindex $ result 0 1]とx2> [lindex $ result 1 0]&y2> [lindex $ result 1 1]を割り当てる必要があります。 "j"に1をつけて、各繰り返しの後にリストから最新の2つのタプルを取ります。最初のリストにはタプルが1つしかないので、2番目のforループは変数を代入することができず、エラーをスローします。 –