Dear all:
I just encountered a problem about number format when I play with a one-bay one story frame. The script is as below:
###############################################################################
wipe
model BasicBuilder -ndm 2 -ndf 3
puts "model geometry"
node 1 0 0
node 2 1 0
node 3 0 1
node 4 1 1
puts "boundary condition"
fix 1 1 1 1
fix 2 1 1 1
puts "Geometry Transformation"
geomTransf Linear 1
set A 1
set E 1
set I [expr 1/12]
puts "element"
element elasticBeamColumn 1 1 3 $A $E $I 1
element elasticBeamColumn 2 3 4 $A $E $I 1
element elasticBeamColumn 3 4 2 $A $E $I 1
#######################################################################
If I apply a lateral load at node 3, the model doesn't work. However, if I change "set I [expr 1/12]" to "set I 0.083" or "set I [expr 13/12]" where value of []>=1, the model works. Also, if I assign variable I to only element 1 and let $I in element 2 and 3 to be a exact number like below:
###########################################################
set A 1
set E 1
set I [expr 1/12]
puts "element"
element elasticBeamColumn 1 1 3 $A $E $I 1
element elasticBeamColumn 2 3 4 $A $E 0.083 1
element elasticBeamColumn 3 4 2 $A $E 0.083 1
########################################################
The model works. Does anyone know why this happens?
Song
number format effect
Moderators: silvia, selimgunay, Moderators
Re: number format effect
your problem is a consequence of integer math
set I [expr 1/12]
1 and 12 are integers, the result is 0
whenever you divide by a value you know not to be an integer always include a dot so the interpreter knws it is not an integer,
i.e. set I [expr 1/12.]
set I [expr 1/12]
1 and 12 are integers, the result is 0
whenever you divide by a value you know not to be an integer always include a dot so the interpreter knws it is not an integer,
i.e. set I [expr 1/12.]