Rev 14851 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 20 | reyssat | 1 | !if $wims_read_parm!=slib_header |
| 2 | !goto proc |
||
| 3 | !endif |
||
| 4180 | bpr | 4 | |
| 4349 | bpr | 5 | slib_author=Georges, KHAZNADAR |
| 4180 | bpr | 6 | |
| 20 | reyssat | 7 | slib_example= ,,,2,2,,1 \ |
| 8 | (distance,m,1000,2000,y*z),(duration,s,10,20,x/z),(velocity,m/s,50,200,x/y),4,2 \ |
||
| 9 | (distance,m,1000,2000,y*z),(duration,s,10,20,x/z),(impossible_velocity,m/s,-50,-10,x/y),4,2 |
||
| 3265 | bpr | 10 | slib_require=pari |
| 20 | reyssat | 11 | !exit |
| 12 | |||
| 13 | :proc |
||
| 14 | |||
| 15 | !reset slib_fx, slib_fy, slib_fz, slib_randx, slib_randy, slib_randz, slib_constx, slib_consty, slib_constz, slib_nl, slib_nc, slib_namex, slib_namey, slib_namez, slib_unitx, slib_unity, slib_unitz, slib_datax, slib_datax, slib_dataz, slib_prec |
||
| 16 | |||
| 17 | slib_parm=!item 1 to 6 of $wims_read_parm |
||
| 18 | !distribute item $slib_parm into slib_datax, slib_datay, slib_dataz, slib_nl, slib_nc, slib_prec, slib_dbg |
||
| 19 | |||
| 20 | !default slib_datax=(I,A,1,10,z/y,(x-1)*(10-x)) |
||
| 21 | !default slib_datay=(R,Ohm,1,10,z/x,(y-1)*(10-y)) |
||
| 22 | !default slib_dataz=(U,V,1,100,x*y,(z-1)*(100-z)) |
||
| 23 | !default slib_nl=3 |
||
| 24 | !default slib_nc=3 |
||
| 25 | !default slib_prec=3 |
||
| 26 | !default slib_dbg=0 |
||
| 27 | |||
| 28 | slib_datax=!declosing $slib_datax |
||
| 29 | slib_datay=!declosing $slib_datay |
||
| 30 | slib_dataz=!declosing $slib_dataz |
||
| 31 | |||
| 32 | slib_namex=$(slib_datax[1]) |
||
| 33 | slib_namey=$(slib_datay[1]) |
||
| 34 | slib_namez=$(slib_dataz[1]) |
||
| 35 | slib_unitx=$(slib_datax[2]) |
||
| 36 | slib_unity=$(slib_datay[2]) |
||
| 37 | slib_unitz=$(slib_dataz[2]) |
||
| 38 | slib_randx=$(slib_datax[3 to 4]) |
||
| 39 | slib_randy=$(slib_datay[3 to 4]) |
||
| 40 | slib_randz=$(slib_dataz[3 to 4]) |
||
| 41 | slib_fx=$(slib_datax[5]) |
||
| 42 | slib_fy=$(slib_datay[5]) |
||
| 43 | slib_fz=$(slib_dataz[5]) |
||
| 44 | slib_constx=$(slib_datax[6]) |
||
| 45 | slib_consty=$(slib_datay[6]) |
||
| 46 | slib_constz=$(slib_dataz[6]) |
||
| 47 | |||
| 48 | !! ==== some expressions which must be constrained to remain positive. ==== |
||
| 49 | !default slib_constx=(x-$(slib_datax[3]))*($(slib_datax[4])-x) |
||
| 50 | !default slib_consty=(y-$(slib_datay[3]))*($(slib_datay[4])-y) |
||
| 51 | !default slib_constz=(z-$(slib_dataz[3]))*($(slib_dataz[4])-z) |
||
| 52 | |||
| 53 | !! ==== list of given x : at least one given, and one unknown. ==== |
||
| 54 | slib_givenx=1,0 |
||
| 55 | |||
| 14851 | bpr | 56 | !! ==== compute a random x1 with significant digits matching the given precision ==== |
| 20 | reyssat | 57 | slib_x1=!random $slib_randx |
| 58 | slib_mul=$[10^($slib_prec-1-floor(lg($slib_x1)))] |
||
| 59 | slib_x1=$[rint($slib_mul*$slib_x1)/$slib_mul] |
||
| 60 | |||
| 61 | !for slib_i from 3 to $slib_nc |
||
| 62 | slib_r=!randint 0,1 |
||
| 63 | slib_givenx=$slib_givenx, $slib_r |
||
| 64 | !if $slib_r=1 |
||
| 14851 | bpr | 65 | !!==== compute a random xi with significant digits matching the given precision ==== |
| 13594 | bpr | 66 | slib_x$slib_i=!random $slib_randx |
| 67 | slib_mul=$[10^($slib_prec-1-floor(lg($(slib_x$slib_i))))] |
||
| 68 | slib_x$slib_i=$[rint($slib_mul*$(slib_x$slib_i))/$slib_mul] |
||
| 20 | reyssat | 69 | !endif |
| 70 | !next slib_i |
||
| 14851 | bpr | 71 | !!==== assert: every given x is an random number between xmin and xmax, ==== |
| 20 | reyssat | 72 | !!==== with no more than prec significant digits. ====================== |
| 73 | |||
| 74 | !! ==== list of given y: at least one given, and one unknown. ==== |
||
| 75 | slib_giveny=1,0 |
||
| 76 | |||
| 7692 | bpr | 77 | |
| 14851 | bpr | 78 | !! ==== compute a random y1 with significant digits matching the given precision ==== |
| 20 | reyssat | 79 | slib_y1=!random $slib_randy |
| 80 | slib_mul=$[10^($slib_prec-1-floor(lg($slib_y1)))] |
||
| 81 | slib_y1=$[rint($slib_mul*$slib_y1)/$slib_mul] |
||
| 82 | |||
| 83 | !for slib_i from 3 to $slib_nl |
||
| 84 | slib_r=!randint 0,1 |
||
| 85 | slib_giveny=$slib_giveny, $slib_r |
||
| 86 | !if $slib_r=1 |
||
| 14851 | bpr | 87 | !!==== compute a random yi with significant digits matching the given precision ==== |
| 13594 | bpr | 88 | slib_y$slib_i=!random $slib_randy |
| 89 | slib_mul=$[10^($slib_prec-1-floor(lg($(slib_y$slib_i))))] |
||
| 90 | slib_y$slib_i=$[rint($slib_mul*$(slib_y$slib_i))/$slib_mul] |
||
| 20 | reyssat | 91 | !endif |
| 92 | !next slib_i |
||
| 14851 | bpr | 93 | !!==== assert: every given y is an random number between ymin and ymax, ==== |
| 20 | reyssat | 94 | !!==== with no more than prec significant digits. ====================== |
| 95 | |||
| 96 | !!==== getting rid of any previous values of z_i_j ==== |
||
| 97 | !for slib_i from 1 to $slib_nc |
||
| 13594 | bpr | 98 | !for slib_j from 1 to $slib_nl |
| 99 | !reset slib_z_$(slib_j)_$(slib_i) |
||
| 100 | !next slib_j |
||
| 20 | reyssat | 101 | !next slib_i |
| 102 | |||
| 103 | !!==== at the begin every z is considered as not given, we shall mark z values as given later ==== |
||
| 104 | slib_givenz=!exec pari matrix($slib_nl,$slib_nc) |
||
| 105 | |||
| 106 | slib_computablex=$slib_givenx |
||
| 107 | slib_computabley=$slib_giveny |
||
| 108 | |||
| 109 | !!==== gathering the non-computable indexes for x ==== |
||
| 110 | slib_first=1 |
||
| 111 | !for slib_i=1 to $slib_nc |
||
| 112 | !if $(slib_computablex[$slib_i]) = 0 |
||
| 113 | !if $slib_first=1 |
||
| 114 | slib_range_noncomputablex=$slib_i |
||
| 115 | slib_first=0 |
||
| 116 | !else |
||
| 117 | slib_range_noncomputablex=$slib_range_noncomputablex, $slib_i |
||
| 118 | !endif |
||
| 119 | !endif |
||
| 120 | !next slib_i |
||
| 121 | !!=== assert : range_noncomputablex is the list of indexes for noncomputable x |
||
| 14851 | bpr | 122 | !for slib_r in $slib_range_noncomputablex |
| 13594 | bpr | 123 | !!==== gather the computable indexes for y ==== |
| 124 | slib_first=1 |
||
| 125 | !for slib_i=1 to $slib_nl |
||
| 126 | !if $(slib_computabley[$slib_i]) = 1 |
||
| 127 | !if $slib_first=1 |
||
| 128 | slib_range_computabley=$slib_i |
||
| 129 | slib_first=0 |
||
| 130 | !else |
||
| 131 | slib_range_computabley=$slib_range_computabley, $slib_i |
||
| 20 | reyssat | 132 | !endif |
| 13594 | bpr | 133 | !endif |
| 134 | !next slib_i |
||
| 14851 | bpr | 135 | !!=== assert : range_computabley is the list of indexes for computable y ==== |
| 13594 | bpr | 136 | slib_s=!randitem $slib_range_computabley |
| 137 | !!==== assert: x is unknown and y is known for column r and row s ==== |
||
| 138 | constraint=-1 |
||
| 139 | maxwhile=20 |
||
| 140 | currentwhile=0 |
||
| 141 | !while $constraint <= 0 |
||
| 142 | currentwhile=$currentwhile+1 |
||
| 143 | !if $currentwhile > $maxwhile |
||
| 144 | !goto too_many_iter |
||
| 145 | !endif |
||
| 146 | slib_z_$(slib_s)_$(slib_r)=!random $slib_randz |
||
| 147 | slib_mul=$[10^($slib_prec-1-floor(lg($(slib_z_$(slib_s)_$(slib_r)))))] |
||
| 148 | slib_z_$(slib_s)_$(slib_r)=$[rint($slib_mul*$(slib_z_$(slib_s)_$(slib_r)))/$slib_mul] |
||
| 149 | expr=!mathsubst y=$(slib_y$(slib_s)) in $slib_fx |
||
| 150 | expr=!mathsubst z=$(slib_z_$(slib_s)_$(slib_r)) in $expr |
||
| 151 | slib_x$(slib_r)=!eval $expr |
||
| 152 | constraint=!mathsubst x=$(slib_x$(slib_r)) in $slib_constx |
||
| 153 | !endwhile |
||
| 154 | !!==== assert: the value of xr is strictly inside the range xmin .. xmax ==== |
||
| 155 | !!==== updating slib_givenz ==== |
||
| 156 | slib_givenz=!exec pari A=Mat([$slib_givenz]);\ |
||
| 14851 | bpr | 157 | B=matrix($slib_nl,$slib_nc,row,col,(row==$slib_s)*(col==$slib_r));\ |
| 158 | print(A+B); |
||
| 13594 | bpr | 159 | slib_givenz=!nospace $slib_givenz |
| 160 | !! updating slib_computablex |
||
| 161 | slib_computablex=!exec pari A=Vec([$slib_computablex]);\ |
||
| 14851 | bpr | 162 | B=vector($slib_nc,x,(x==$slib_r));\ |
| 163 | A+B |
||
| 13594 | bpr | 164 | slib_computablex=!nospace $slib_computablex |
| 7692 | bpr | 165 | !next slib_r |
| 20 | reyssat | 166 | !!==== assert: every x is computable ==== |
| 167 | |||
| 168 | !!==== gathering the non-computable indexes for y ==== |
||
| 169 | slib_first=1 |
||
| 170 | !for slib_i=1 to $slib_nl |
||
| 171 | !if $(slib_computabley[$slib_i]) = 0 |
||
| 172 | !if $slib_first=1 |
||
| 173 | slib_range_noncomputabley=$slib_i |
||
| 174 | slib_first=0 |
||
| 175 | !else |
||
| 176 | slib_range_noncomputabley=$slib_range_noncomputabley, $slib_i |
||
| 177 | !endif |
||
| 178 | !endif |
||
| 179 | !next slib_i |
||
| 180 | !!=== assert : range_noncomputabley is the list of indexes for noncomputable y |
||
| 14851 | bpr | 181 | !for slib_s in $slib_range_noncomputabley |
| 13594 | bpr | 182 | !!==== gather the computable indexes for x ==== |
| 183 | slib_first=1 |
||
| 184 | !for slib_i=1 to $slib_nc |
||
| 185 | !if $(slib_computablex[$slib_i]) = 1 |
||
| 186 | !if $slib_first=1 |
||
| 187 | slib_range_computablex=$slib_i |
||
| 188 | slib_first=0 |
||
| 189 | !else |
||
| 190 | slib_range_computablex=$slib_range_computablex, $slib_i |
||
| 20 | reyssat | 191 | !endif |
| 13594 | bpr | 192 | !endif |
| 193 | !next slib_i |
||
| 14851 | bpr | 194 | !!=== assert : range_computablex is the list of indexes for computable x ==== |
| 13594 | bpr | 195 | slib_r=!randitem $slib_range_computablex |
| 196 | !!==== assert: x is known and y is unknown for column r and row s ==== |
||
| 197 | constraint=-1 |
||
| 198 | !while $constraint <= 0 |
||
| 199 | slib_z_$(slib_s)_$(slib_r)=!random $slib_randz |
||
| 200 | slib_mul=$[10^($slib_prec-1-floor(lg($(slib_z_$(slib_s)_$(slib_r)))))] |
||
| 201 | slib_z_$(slib_s)_$(slib_r)=$[rint($slib_mul*$(slib_z_$(slib_s)_$(slib_r)))/$slib_mul] |
||
| 202 | expr=!mathsubst x=$(slib_x$(slib_r)) in $slib_fy |
||
| 203 | expr=!mathsubst z=$(slib_z_$(slib_s)_$(slib_r)) in $expr |
||
| 204 | slib_y$(slib_s)=!eval $expr |
||
| 205 | constraint=!mathsubst y=$(slib_y$(slib_s)) in $slib_consty |
||
| 206 | !endwhile |
||
| 207 | !!==== assert: the value of ys is strictly inside the range ymin .. ymax ==== |
||
| 208 | !!==== updating slib_givenz ==== |
||
| 209 | slib_givenz=!exec pari A=Mat([$slib_givenz]);\ |
||
| 14851 | bpr | 210 | B=matrix($slib_nl,$slib_nc,row,col,(row==$slib_s)*(col==$slib_r));\ |
| 211 | print(A+B); |
||
| 13594 | bpr | 212 | slib_givenz=!nospace $slib_givenz |
| 213 | !! updating slib_computabley |
||
| 214 | slib_computabley=!exec pari A=Vec([$slib_computabley]);\ |
||
| 14851 | bpr | 215 | B=vector($slib_nl,y,(y==$slib_s)); A+B |
| 13594 | bpr | 216 | slib_computabley=!nospace $slib_computabley |
| 20 | reyssat | 217 | !next slib_s |
| 218 | !!==== assert: every y is computable ==== |
||
| 219 | |||
| 220 | !!computing the non-given z_s_r |
||
| 221 | !for slib_s=1 to $slib_nl |
||
| 13594 | bpr | 222 | !for slib_r=1 to $slib_nc |
| 223 | !!==== if z is not given we compute it from x and y ==== |
||
| 224 | !if $(slib_givenz[$slib_s;$slib_r]) = 0 |
||
| 225 | expr=!mathsubst x=$(slib_x$slib_r) in $slib_fz |
||
| 226 | expr=!mathsubst y=$(slib_y$slib_s) in $expr |
||
| 227 | expr=!eval ($expr) |
||
| 228 | slib_z_$(slib_s)_$(slib_r)=$expr |
||
| 229 | !endif |
||
| 230 | !next slib_r |
||
| 20 | reyssat | 231 | !next slib_s |
| 232 | |||
| 233 | slib_shx=!shuffle $slib_nc |
||
| 234 | slib_shy=!shuffle $slib_nl |
||
| 235 | |||
| 236 | slib_reply=1 |
||
| 237 | slib_replies= |
||
| 238 | !! slib_t will be a list of chunks of code to make a table when interleaved |
||
| 239 | !! with slib_replies |
||
| 240 | slib_t= |
||
| 14851 | bpr | 241 | slib_t=<table class="wimsborder"><tr><th style='background-color:#AAFFAA' colspan="2" rowspan="2">$slib_namez ($slib_unitz)</th><th style='background-color:yellow;text-align:center' colspan="$slib_nc">$slib_namex ($slib_unitx)</th></tr><tr> |
| 20 | reyssat | 242 | !for slib_i=1 to $slib_nc |
| 243 | slib_c=$(slib_shx[$slib_i]) |
||
| 244 | !if $(slib_givenx[$slib_c])=1 |
||
| 13594 | bpr | 245 | slib_t=$slib_t <td bgcolor='yellow'>$(slib_x$slib_c) $slib_unitx</td> |
| 20 | reyssat | 246 | !else |
| 14851 | bpr | 247 | slib_t=$slib_t <td style='background-color:yellow;padding:8'>, |
| 13594 | bpr | 248 | slib_replies=$slib_replies $(slib_x$slib_c) $slib_unitx, |
| 249 | slib_reply=$[$slib_reply+1] |
||
| 250 | slib_t=$slib_t </td> |
||
| 20 | reyssat | 251 | !endif |
| 252 | !next slib_i |
||
| 253 | |||
| 254 | !!<tr><td> |
||
| 255 | !for slib_j=1 to $slib_nl |
||
| 13594 | bpr | 256 | slib_l=$(slib_shy[$slib_j]) |
| 257 | slib_t=$slib_t </tr><tr> |
||
| 258 | !if $slib_j=1 |
||
| 17173 | bpr | 259 | slib_t=$slib_t <th style='background-color:lightblue;vertical-align:medium' rowspan='$slib_nl'>$slib_namey<br>($slib_unity)</th> |
| 13594 | bpr | 260 | !endif |
| 261 | !if $(slib_giveny[$slib_l])=1 |
||
| 262 | slib_t=$slib_t <td bgcolor='lightblue'>$(slib_y$slib_l) $slib_unity</td> |
||
| 20 | reyssat | 263 | !else |
| 14851 | bpr | 264 | slib_t=$slib_t <td style='background-color:lightblue;padding:8'>, |
| 13594 | bpr | 265 | slib_replies=$slib_replies $(slib_y$slib_l) $slib_unity, |
| 266 | slib_reply=$[$slib_reply+1] |
||
| 267 | slib_t=$slib_t </td> |
||
| 20 | reyssat | 268 | !endif |
| 13594 | bpr | 269 | !for slib_i=1 to $slib_nc |
| 270 | slib_c=$(slib_shx[$slib_i]) |
||
| 271 | !if $(slib_givenz[$slib_l;$slib_c])=1 |
||
| 14851 | bpr | 272 | slib_t=$slib_t <td style='background-color:#AAFFAA>'>$(slib_z_$(slib_l)_$(slib_c)) $slib_unitz</td> |
| 13594 | bpr | 273 | !else |
| 14851 | bpr | 274 | slib_t=$slib_t <td style='background-color:#AAFFAA;padding:8'>, |
| 13594 | bpr | 275 | slib_replies=$slib_replies $(slib_z_$(slib_l)_$(slib_c)) $slib_unitz, |
| 276 | slib_reply=$[$slib_reply+1] |
||
| 277 | slib_t=$slib_t </td> |
||
| 278 | !endif |
||
| 279 | !next slib_i |
||
| 20 | reyssat | 280 | !next slib_j |
| 281 | slib_t=$slib_t</tr></table> |
||
| 282 | |||
| 283 | slib_reply=$[$slib_reply-1] |
||
| 284 | slib_replies=$(slib_replies[1 to $slib_reply]) |
||
| 285 | |||
| 286 | slib_table=$(slib_t[1]) |
||
| 287 | !for slib_i=1 to $slib_reply |
||
| 13594 | bpr | 288 | !if $slib_dbg=1 |
| 17173 | bpr | 289 | slib_table=$slib_table <input type='text' name='reply$slib_i' value='$(slib_replies[$slib_i])'> $(slib_t[$[$slib_i+1]]) |
| 13594 | bpr | 290 | !else |
| 17173 | bpr | 291 | slib_table=$slib_table <input type='text' name='reply$slib_i'> $(slib_t[$[$slib_i+1]]) |
| 13594 | bpr | 292 | !endif |
| 20 | reyssat | 293 | !next slib_i |
| 294 | |||
| 295 | slib_out= $slib_table, $slib_reply, $slib_replies, $slib_t |
||
| 296 | !goto end |
||
| 297 | |||
| 298 | :too_many_iter |
||
| 299 | slib_out= Error. Please inform the developer that have been too many iterations while trying to satisfy the constraints to adjust a variable. This is very unlikely to occur. Please verify whether the constraint set is compatible with the relations linking the variables and their allowed intervals of validity. If you are visiting the help system, the error was triggered by the impossible_velocity validity interval. |
||
| 300 | |||
| 7692 | bpr | 301 | :end |