1@menu
2* Introduction to wrstcse::
3* Functions and Variables for wrstcse::
4@end menu
5
6@node Introduction to wrstcse, Functions and Variables for wrstcse, wrstcse-pkg, wrstcse-pkg
7@section Introduction to wrstcse
8
9@code{wrstcse} is a naive go at interval arithmetics is powerful enough to
10perform worst case calculations that appear in engineering by applying
11all combinations of tolerances to all parameters.
12
13This approach isn't guaranteed to find the exact combination of parameters
14that results in the worst-case. But it avoids the problems that make a true
15interval arithmetics affected by the halting problem as an equation can have
16an infinite number of local minima and maxima and it might be impossible to
17algorithmically determine which one is the global one.
18
19Tolerances are applied to parameters by providing the parameter with a @var{tol[n]}
20that wrstcase will vary between -1 and 1. Using the same @var{n} for two parameters
21will make both parameters tolerate in the same way.
22
23@code{load ("wrstcse")} loads this package.
24
25@opencatbox
26@category{Share packages}
27@category{Package wrstcse}
28@closecatbox
29
30@node Functions and Variables for wrstcse, , Introduction to wrstcse, wrstcse-pkg
31@section Functions and Variables for wrstcse
32
33@anchor{wc_typicalvalues}
34@deffn {Function} wc_typicalvalues (@var{expression}, [@var{num}])
35
36Returns what happens if all tolerances (that are represented by tol [n] that can
37vary from 0 to 1) happen to be 0.
38
39Example:
40@c ===beg===
41@c load("wrstcse")$
42@c vals: [
43@c    R_1= 1000.0*(1+tol[1]*.01),
44@c    R_2= 2000.0*(1+tol[2]*.01)
45@c  ];
46@c divider:U_Out=U_In*R_1/(R_1+R_2);
47@c wc_typicalvalues(vals);
48@c wc_typicalvalues(subst(vals,divider));
49@c ===end===
50@example
51(%i1) load("wrstcse")$
52@group
53(%i2) vals: [
54   R_1= 1000.0*(1+tol[1]*.01),
55   R_2= 2000.0*(1+tol[2]*.01)
56 ];
57(%o2) [R_1 = 1000.0 (0.01 tol  + 1),
58                             1
59                                    R_2 = 2000.0 (0.01 tol  + 1)]
60                                                          2
61@end group
62@group
63(%i3) divider:U_Out=U_In*R_1/(R_1+R_2);
64                                R_1 U_In
65(%o3)                   U_Out = ---------
66                                R_2 + R_1
67@end group
68@group
69(%i4) wc_typicalvalues(vals);
70(%o4)             [R_1 = 1000.0, R_2 = 2000.0]
71@end group
72@group
73(%i5) wc_typicalvalues(subst(vals,divider));
74(%o5)            U_Out = 0.3333333333333333 U_In
75@end group
76@end example
77@end deffn
78
79@anchor{wc_inputvalueranges}
80@deffn {Function} wc_inputvalueranges (@var{expression}, [@var{num}])
81
82Convenience function: Displays a list which parameter can vary between
83which values.
84
85Example:
86@c ===beg===
87@c load("wrstcse")$
88@c vals: [
89@c    R_1= 1000.0*(1+tol[1]*.01),
90@c    R_2= 2000.0*(1+tol[2]*.01)
91@c  ];
92@c wc_inputvalueranges(vals);
93@c ===end===
94@example
95(%i1) load("wrstcse")$
96@group
97(%i2) vals: [
98   R_1= 1000.0*(1+tol[1]*.01),
99   R_2= 2000.0*(1+tol[2]*.01)
100 ];
101(%o2) [R_1 = 1000.0 (0.01 tol  + 1),
102                             1
103                                    R_2 = 2000.0 (0.01 tol  + 1)]
104                                                          2
105@end group
106@group
107(%i3) wc_inputvalueranges(vals);
108        [ R_1  min = 990.0   typ = 1000.0  max = 1010.0 ]
109(%o3)   [                                               ]
110        [ R_2  min = 1980.0  typ = 2000.0  max = 2020.0 ]
111@end group
112@end example
113@end deffn
114
115@anchor{wc_systematic}
116@deffn {Function} wc_systematic (@var{expression}, [@var{num}])
117
118Systematically introduces @var{num} values per parameter into @var{expression}
119and returns a list of the result. If no @var{num} is given, @var{num} defaults
120to 3.
121
122See also @mrefdot{wc_montecarlo}
123
124Example:
125@c ===beg===
126@c load("wrstcse")$
127@c vals: [
128@c    R_1= 1000.0*(1+tol[1]*.01),
129@c    R_2= 2000.0*(1+tol[2]*.01)
130@c  ];
131@c divider: U_Out=U_In*(R_1)/(R_1+R_2);
132@c wc_systematic(subst(vals,rhs(divider)));
133@c ===end===
134@example
135(%i1) load("wrstcse")$
136@group
137(%i2) vals: [
138   R_1= 1000.0*(1+tol[1]*.01),
139   R_2= 2000.0*(1+tol[2]*.01)
140 ];
141(%o2) [R_1 = 1000.0 (0.01 tol  + 1),
142                             1
143                                    R_2 = 2000.0 (0.01 tol  + 1)]
144                                                          2
145@end group
146@group
147(%i3) divider: U_Out=U_In*(R_1)/(R_1+R_2);
148                                R_1 U_In
149(%o3)                   U_Out = ---------
150                                R_2 + R_1
151@end group
152@group
153(%i4) wc_systematic(subst(vals,rhs(divider)));
154(%o4) [0.3333333333333334 U_In, 0.3311036789297659 U_In,
1550.3289036544850498 U_In, 0.3355704697986577 U_In,
1560.3333333333333333 U_In, 0.3311258278145696 U_In,
1570.3377926421404682 U_In, 0.3355481727574751 U_In,
1580.3333333333333333 U_In]
159@end group
160@end example
161@end deffn
162
163@anchor{wc_montecarlo}
164@deffn {Function} wc_montecarlo (@var{expression}, @var{num})
165
166Introduces @var{num} random values per parameter into
167@var{expression} and returns a list of the result.
168
169See also @mrefdot{wc_systematic}
170
171Example:
172@c ===beg===
173@c load("wrstcse")$
174@c vals: [
175@c    R_1= 1000.0*(1+tol[1]*.01),
176@c    R_2= 2000.0*(1+tol[2]*.01)
177@c  ];
178@c divider: U_Out=U_In*(R_1)/(R_1+R_2);
179@c wc_montecarlo(subst(vals,rhs(divider)),10);
180@c ===end===
181@example
182(%i1) load("wrstcse")$
183@group
184(%i2) vals: [
185   R_1= 1000.0*(1+tol[1]*.01),
186   R_2= 2000.0*(1+tol[2]*.01)
187 ];
188(%o2) [R_1 = 1000.0 (0.01 tol  + 1),
189                             1
190                                    R_2 = 2000.0 (0.01 tol  + 1)]
191                                                          2
192@end group
193@group
194(%i3) divider: U_Out=U_In*(R_1)/(R_1+R_2);
195                                R_1 U_In
196(%o3)                   U_Out = ---------
197                                R_2 + R_1
198@end group
199@group
200(%i4) wc_montecarlo(subst(vals,rhs(divider)),10);
201(%o4) [0.3365488313167528 U_In, 0.3339089445851889 U_In,
2020.314651402884122 U_In, 0.3447359711624277 U_In,
2030.3294005710066001 U_In, 0.3330897542463686 U_In,
2040.3397591863729343 U_In, 0.3227030530673181 U_In,
2050.3385512773502185 U_In, 0.314764470912582 U_In]
206@end group
207@end example
208@end deffn
209
210@anchor{wc_mintypmax}
211@deffn {Function} wc_mintypmax (@var{expr}, [@var{n}])
212
213Prints the minimum, maximum and typical value of @var{expr}. If @var{n}
214is positive, @var{n} values for each parameter will be tried systematically.
215If @var{n} is negative, @var{-n} random values are used instead.
216If no @var{n} is given, 3 is assumed.
217
218Example:
219@c ===beg===
220@c load("wrstcse")$
221@c ratprint:false$
222@c vals: [
223@c    R_1= 1000.0*(1+tol[1]*.01),
224@c    R_2= 1000.0*(1+tol[2]*.01)
225@c  ];
226@c assume(U_In>0);
227@c divider:U_Out=U_In*R_1/(R_1+R_2);
228@c lhs(divider)=wc_mintypmax(subst(vals,rhs(divider)));
229@c ===end===
230@example
231(%i1) load("wrstcse")$
232(%i2) ratprint:false$
233@group
234(%i3) vals: [
235   R_1= 1000.0*(1+tol[1]*.01),
236   R_2= 1000.0*(1+tol[2]*.01)
237 ];
238(%o3) [R_1 = 1000.0 (0.01 tol  + 1),
239                             1
240                                    R_2 = 1000.0 (0.01 tol  + 1)]
241                                                          2
242@end group
243@group
244(%i4) assume(U_In>0);
245(%o4)                      [U_In > 0]
246@end group
247@group
248(%i5) divider:U_Out=U_In*R_1/(R_1+R_2);
249                                R_1 U_In
250(%o5)                   U_Out = ---------
251                                R_2 + R_1
252@end group
253@group
254(%i6) lhs(divider)=wc_mintypmax(subst(vals,rhs(divider)));
255(%o6) U_Out = [min = 0.495 U_In, typ = 0.5 U_In,
256                                                max = 0.505 U_In]
257@end group
258@end example
259@end deffn
260
261@anchor{wc_tolappend}
262@deffn {Function} wc_tolappend (@var{list})
263
264Appends two list of parameters with tolerances renumbering the tolerances of
265both lists so they don't coincide.
266
267Example:
268@c ===beg===
269@c load("wrstcse")$
270@c val_a: [
271@c    R_1= 1000.0*(1+tol[1]*.01),
272@c    R_2= 1000.0*(1+tol[2]*.01)
273@c  ];
274@c val_b: [
275@c    R_3= 1000.0*(1+tol[1]*.01),
276@c    R_4= 1000.0*(1+tol[2]*.01)
277@c  ];
278@c wc_tolappend(val_a,val_b);
279@c ===end===
280@example
281(%i1) load("wrstcse")$
282@group
283(%i2) val_a: [
284   R_1= 1000.0*(1+tol[1]*.01),
285   R_2= 1000.0*(1+tol[2]*.01)
286 ];
287(%o2) [R_1 = 1000.0 (0.01 tol  + 1),
288                             1
289                                    R_2 = 1000.0 (0.01 tol  + 1)]
290                                                          2
291@end group
292@group
293(%i3) val_b: [
294   R_3= 1000.0*(1+tol[1]*.01),
295   R_4= 1000.0*(1+tol[2]*.01)
296 ];
297(%o3) [R_3 = 1000.0 (0.01 tol  + 1),
298                             1
299                                    R_4 = 1000.0 (0.01 tol  + 1)]
300                                                          2
301@end group
302@group
303(%i4) wc_tolappend(val_a,val_b);
304(%o4) [R_1 = 1000.0 (0.01 tol  + 1),
305                             2
306R_2 = 1000.0 (0.01 tol  + 1), R_3 = 1000.0 (0.01 tol  + 1),
307                      1                             4
308R_4 = 1000.0 (0.01 tol  + 1)]
309                      3
310@end group
311@end example
312@end deffn
313
314@anchor{wc_mintypmax2tol}
315@deffn {Function} wc_mintypmax2tol (@var{tolname}, @var{minval}, @var{typval}, @var{maxval})
316
317Generates a parameter that uses the tolerance @var{tolname} that tolerates between the
318given values.
319
320Example:
321@c ===beg===
322@c load("wrstcse")$
323@c V_F: U_Diode=wc_mintypmax2tol(tol[1],.5,.75,.82);
324@c lhs(V_F)=wc_mintypmax(rhs(V_F));
325@c ===end===
326@example
327(%i1) load("wrstcse")$
328@group
329(%i2) V_F: U_Diode=wc_mintypmax2tol(tol[1],.5,.75,.82);
330                                          2
331(%o2) U_Diode = (- 0.09000000000000002 tol ) + 0.16 tol  + 0.75
332                                          1            1
333@end group
334@group
335(%i3) lhs(V_F)=wc_mintypmax(rhs(V_F));
336(%o3) U_Diode = [min = 0.5, typ = 0.75, max = 0.8199999999999998]
337@end group
338@end example
339@end deffn
340