1 | import math |
---|
2 | |
---|
3 | def toX(x,y=None): |
---|
4 | """ |
---|
5 | This function is used to load value on Plottable.View |
---|
6 | @param x: Float value |
---|
7 | @return x, |
---|
8 | """ |
---|
9 | return x |
---|
10 | |
---|
11 | def toX2(x,y=None): |
---|
12 | """ |
---|
13 | This function is used to load value on Plottable.View |
---|
14 | Calculate x^(2) |
---|
15 | @param x: float value |
---|
16 | """ |
---|
17 | return x*x |
---|
18 | |
---|
19 | def fromX2(x,y=None): |
---|
20 | """ |
---|
21 | This function is used to load value on Plottable.View |
---|
22 | Calculate square root of x |
---|
23 | @param x: float value |
---|
24 | """ |
---|
25 | if not x >=0 : |
---|
26 | raise ValueError, "square root of a negative value " |
---|
27 | else: |
---|
28 | return math.sqrt(x) |
---|
29 | def toLogX(x,y=None): |
---|
30 | """ |
---|
31 | This function is used to load value on Plottable.View |
---|
32 | calculate log x |
---|
33 | @param x: float value |
---|
34 | """ |
---|
35 | if not x > 0: |
---|
36 | raise ValueError, "Log(X)of a negative value " |
---|
37 | else: |
---|
38 | return math.log(x) |
---|
39 | |
---|
40 | def toOneOverX(x,y=None): |
---|
41 | if x !=0: |
---|
42 | return 1/x |
---|
43 | else: |
---|
44 | raise ValueError,"cannot divide by zero" |
---|
45 | def toOneOverSqrtX(y , x=None): |
---|
46 | if y!=None: |
---|
47 | if y > 0: |
---|
48 | return 1/math.sqrt(y) |
---|
49 | else: |
---|
50 | raise ValueError,"cannot be computed" |
---|
51 | |
---|
52 | |
---|
53 | def toLogYX2(y,x): |
---|
54 | if y*(x**2) >0: |
---|
55 | return math.log(y*(x**2)) |
---|
56 | else: |
---|
57 | raise ValueError,"cannot be computed" |
---|
58 | |
---|
59 | |
---|
60 | def toLogYX4(y, x): |
---|
61 | if math.pow(x,4)*y > 0: |
---|
62 | return math.log(math.pow(x,4)*y) |
---|
63 | |
---|
64 | def toLogXY(y,x): |
---|
65 | """ |
---|
66 | This function is used to load value on Plottable.View |
---|
67 | calculate log x |
---|
68 | @param x: float value |
---|
69 | """ |
---|
70 | if not x*y > 0: |
---|
71 | raise ValueError, "Log(X*Y)of a negative value " |
---|
72 | else: |
---|
73 | return math.log(x*y) |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | def errToX(x,y=None,dx=None,dy=None): |
---|
78 | """ |
---|
79 | calculate error of x**2 |
---|
80 | @param x: float value |
---|
81 | @param dx: float value |
---|
82 | """ |
---|
83 | if dx==None: |
---|
84 | dx=0 |
---|
85 | return dx |
---|
86 | |
---|
87 | |
---|
88 | def errToX2(x,y=None,dx=None,dy=None): |
---|
89 | """ |
---|
90 | calculate error of x**2 |
---|
91 | @param x: float value |
---|
92 | @param dx: float value |
---|
93 | """ |
---|
94 | if dx != None: |
---|
95 | err = 2*x*dx |
---|
96 | if math.fabs(err) >= math.fabs(x): |
---|
97 | err = 0.9*x |
---|
98 | return math.fabs(err) |
---|
99 | else: |
---|
100 | return 0.0 |
---|
101 | def errFromX2(x,y=None,dx=None,dy=None): |
---|
102 | """ |
---|
103 | calculate error of sqrt(x) |
---|
104 | @param x: float value |
---|
105 | @param dx: float value |
---|
106 | """ |
---|
107 | if (x > 0): |
---|
108 | if(dx != None): |
---|
109 | err = dx/(2*math.sqrt(x)) |
---|
110 | else: |
---|
111 | err = 0 |
---|
112 | if math.fabs(err) >= math.fabs(x): |
---|
113 | err = 0.9*x |
---|
114 | else: |
---|
115 | err = 0.9*x |
---|
116 | |
---|
117 | return math.fabs(err) |
---|
118 | |
---|
119 | def errToLogX(x,y=None,dx=None,dy=None): |
---|
120 | """ |
---|
121 | calculate error of Log(x) |
---|
122 | @param x: float value |
---|
123 | @param dx: float value |
---|
124 | """ |
---|
125 | if dx==None: |
---|
126 | dx = 0 |
---|
127 | if x!=0: |
---|
128 | dx = dx/x |
---|
129 | else: |
---|
130 | raise ValueError, "errToLogX: divide by zero" |
---|
131 | |
---|
132 | if math.fabs(dx) >= math.fabs(x): |
---|
133 | dx = 0.9*x |
---|
134 | |
---|
135 | return dx |
---|
136 | |
---|
137 | def errToXY(x, y, dx=None, dy=None): |
---|
138 | if dx==None: |
---|
139 | dx=0 |
---|
140 | if dy==None: |
---|
141 | dy=0 |
---|
142 | err =math.sqrt((y*dx)**2 +(x*dy)**2) |
---|
143 | if err >= math.fabs(x): |
---|
144 | err =0.9*x |
---|
145 | return err |
---|
146 | |
---|
147 | def errToYX2(x, y, dx=None, dy=None): |
---|
148 | if dx==None: |
---|
149 | dx=0 |
---|
150 | if dy==None: |
---|
151 | dy=0 |
---|
152 | err =math.sqrt((2*x*y*dx)**2 +((x**2)*dy)**2) |
---|
153 | if err >= math.fabs(x): |
---|
154 | err =0.9*x |
---|
155 | return err |
---|
156 | |
---|
157 | def errToLogXY(x,y,dx=None, dy=None): |
---|
158 | """ |
---|
159 | calculate error of Log(xy) |
---|
160 | """ |
---|
161 | if (x!=0) and (y!=0): |
---|
162 | if dx == None: |
---|
163 | dx = 0 |
---|
164 | if dy == None: |
---|
165 | dy = 0 |
---|
166 | err = (dx/x)**2 + (dy/y)**2 |
---|
167 | if math.sqrt(math.fabs(err)) >= math.fabs(x): |
---|
168 | err= 0.9*x |
---|
169 | else: |
---|
170 | raise ValueError, "cannot compute this error" |
---|
171 | |
---|
172 | return math.sqrt(math.fabs(err)) |
---|
173 | |
---|
174 | def errToLogYX2(x,y,dx=None, dy=None): |
---|
175 | """ |
---|
176 | calculate error of Log(yx**2) |
---|
177 | """ |
---|
178 | if (x > 0) and (y > 0): |
---|
179 | if (dx == None): |
---|
180 | dx = 0 |
---|
181 | if (dy == None): |
---|
182 | dy = 0 |
---|
183 | err = (2*dx/x)**2 + (dy/y)**2 |
---|
184 | if math.fabs(err) >= math.fabs(x): |
---|
185 | err =0.9*x |
---|
186 | else: |
---|
187 | raise ValueError, "cannot compute this error" |
---|
188 | |
---|
189 | return math.sqrt(math.fabs(err)) |
---|
190 | |
---|
191 | def errOneOverX(x,y=None,dx=None, dy=None): |
---|
192 | """ |
---|
193 | calculate error on 1/x |
---|
194 | """ |
---|
195 | if (x != 0): |
---|
196 | if dx ==None: |
---|
197 | dx= 0 |
---|
198 | err = -(dx)**2/x**2 |
---|
199 | else: |
---|
200 | raise ValueError,"Cannot compute this error" |
---|
201 | |
---|
202 | if math.fabs(err)>= math.fabs(x): |
---|
203 | err= 0.9*x |
---|
204 | return math.fabs(err) |
---|
205 | |
---|
206 | def errOneOverSqrtX(x,y=None, dx=None,dy=None): |
---|
207 | """ |
---|
208 | Calculate error on 1/sqrt(x) |
---|
209 | """ |
---|
210 | if (x >0): |
---|
211 | if dx==None: |
---|
212 | dx =0 |
---|
213 | err= -1/2*math.pow(x, -3/2)* dx |
---|
214 | if math.fabs(err)>= math.fabs(x): |
---|
215 | err=0.9*x |
---|
216 | else: |
---|
217 | raise ValueError, "Cannot compute this error" |
---|
218 | |
---|
219 | return math.fabs(err) |
---|
220 | def errToLogYX4(x,y=None,dx=None,dy=None): |
---|
221 | """ |
---|
222 | error for ln(y*x^(4)) |
---|
223 | @param x: float value |
---|
224 | """ |
---|
225 | if dx==None: |
---|
226 | dx=0 |
---|
227 | if dy==None: |
---|
228 | dy=0 |
---|
229 | err =math.sqrt((4*dx/x)**2 +(dy/y)**2) |
---|
230 | if err >= math.fabs(x): |
---|
231 | err =0.9*x |
---|
232 | return err |
---|
233 | |
---|
234 | |
---|