Subversion Repositories wimsdev

Rev

Rev 20 | Rev 4158 | Go to most recent revision | 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
686 bpr 4
slib_title=The bound of a real function of two variables within a rectangle [x1,x2],[y1,y2]
20 reyssat 5
slib_parms=7\
6
,the function expression\
7
[x,y],the variable names\
8
0,x1\
9
1,x2\
10
0,y1\
11
1,y2\
12
50,number of cutting steps (<=1000)
13
slib_author=Bernadette Perrin-Riou
14
slib_out=min,max
15
slib_comment=This script computes the minimum and the maximum of a function\
16
 of two variables within a rectangle, in a very approximative way. Its main purpose is for\
17
 plotting uses.
18
 slib_example=x^2+sin(x*y)+exp(y^2),[x,y],0,3,-3,2,50
19
 
20
!exit
21
 
22
:proc
23
!distribute items $wims_read_parm into slib_fn,slib_var,slib_x1,slib_x2,slib_y1,slib_y2,slib_steps
24
slib_fn=!rawmath $slib_fn
25
slib_var=!declosing $slib_var
26
slib_var1=!item 1 of $slib_var
27
slib_var2=!item 2 of $slib_var
28
!default slib_var1=x
29
!default slib_var2=y
30
slib_x1=$[$slib_x1]
31
!if $slib_x1=$empty or $slib_x1 isitemof NaN,Inf
32
	 slib_x1=0
33
!endif
34
slib_x2=$[$slib_x2]
35
!if $slib_x2=$empty or $slib_x2 isitemof NaN,Inf
36
	 slib_x2=1
37
!endif
38
slib_y1=$[$slib_y1]
39
!if $slib_y1=$empty or $slib_y1 isitemof NaN,Inf
40
 slib_y1=0
41
!endif
42
slib_y2=$[$slib_y2]
43
!if $slib_y2=$empty or $slib_y2 isitemof NaN,Inf
44
 slib_x2=1
45
!endif
46
!bound slib_steps between integer 1 and 1000 default 50
47
!bound slib_steps2 between integer 1 and 1000 default 50
48
slib_step=$[($slib_x2-($slib_x1))/$slib_steps]
49
slib_step2=$[($slib_y2-($slib_y1))/$slib_steps]
50
slib_min=$empty
51
slib_max=$empty
52
 
53
!for slib_i=0 to $slib_steps
54
	slib_fxn=!mathsubst $slib_var1= $[$slib_x1+$slib_i*$slib_step] in $slib_fn
55
	slib_fxn=!replace item NaN by $ in $slib_fxn
56
	slib_vals=!values $slib_fxn for $slib_var2=$slib_y1 to $slib_y2 step $slib_step
57
	slib_vals=!replace item NaN by $ in $slib_vals
58
	slib_vals=!nonempty items $slib_vals
59
	!if $slib_i>1 
60
		slib_vals=!sort numeric items $slib_min,$slib_vals,$slib_max
61
	!else
62
		slib_vals=!sort numeric items $slib_vals
63
	!endif
64
	slib_vals=!trim $slib_vals
65
	slib_min=!item 1 of $slib_vals
66
	slib_max=!item -1 of $slib_vals
67
!next slib_i
68
 
69
slib_out=$slib_min,$slib_max