[831149e] | 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" |
---|
[f193585] | 45 | def toOneOverSqrtX(y , x=None): |
---|
[831149e] | 46 | if y!=None: |
---|
| 47 | if y > 0: |
---|
| 48 | return 1/math.sqrt(y) |
---|
| 49 | else: |
---|
| 50 | raise ValueError,"cannot be computed" |
---|
| 51 | |
---|
[f193585] | 52 | |
---|
| 53 | def toLogYX2(y,x): |
---|
[831149e] | 54 | if y*(x**2) >0: |
---|
| 55 | return math.log(y*(x**2)) |
---|
| 56 | else: |
---|
| 57 | raise ValueError,"cannot be computed" |
---|
| 58 | |
---|
| 59 | |
---|
[f193585] | 60 | def toLogYX4(y, x): |
---|
[831149e] | 61 | if math.pow(x,4)*y > 0: |
---|
| 62 | return math.log(math.pow(x,4)*y) |
---|
| 63 | |
---|
[f193585] | 64 | def toLogXY(y,x): |
---|
[831149e] | 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) |
---|
[8e44d51] | 74 | |
---|
[831149e] | 75 | |
---|
[46693050] | 76 | |
---|
[831149e] | 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 | """ |
---|
[f193585] | 83 | if dx==None: |
---|
| 84 | dx=0 |
---|
[831149e] | 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) |
---|
[2e07e8f] | 118 | def errToLog10X(x,y=None,dx=None,dy=None): |
---|
| 119 | """ |
---|
| 120 | calculate error of Log(x) |
---|
| 121 | @param x: float value |
---|
| 122 | @param dx: float value |
---|
| 123 | """ |
---|
| 124 | if dx==None: |
---|
| 125 | dx = 0 |
---|
| 126 | if x!=0: |
---|
| 127 | dx = dx/(x*math.log(10)) |
---|
| 128 | else: |
---|
| 129 | raise ValueError, "errToLogX: divide by zero" |
---|
| 130 | |
---|
| 131 | if math.fabs(dx) >= math.fabs(x): |
---|
| 132 | dx = 0.9*x |
---|
| 133 | |
---|
| 134 | return dx |
---|
[831149e] | 135 | |
---|
| 136 | def errToLogX(x,y=None,dx=None,dy=None): |
---|
| 137 | """ |
---|
| 138 | calculate error of Log(x) |
---|
| 139 | @param x: float value |
---|
| 140 | @param dx: float value |
---|
| 141 | """ |
---|
| 142 | if dx==None: |
---|
| 143 | dx = 0 |
---|
[46693050] | 144 | if x!=0: |
---|
| 145 | dx = dx/x |
---|
| 146 | else: |
---|
| 147 | raise ValueError, "errToLogX: divide by zero" |
---|
| 148 | |
---|
[831149e] | 149 | if math.fabs(dx) >= math.fabs(x): |
---|
[46693050] | 150 | dx = 0.9*x |
---|
| 151 | |
---|
[831149e] | 152 | return dx |
---|
| 153 | |
---|
[2e014bf] | 154 | |
---|
[831149e] | 155 | |
---|
| 156 | def errToYX2(x, y, dx=None, dy=None): |
---|
| 157 | if dx==None: |
---|
| 158 | dx=0 |
---|
| 159 | if dy==None: |
---|
| 160 | dy=0 |
---|
| 161 | err =math.sqrt((2*x*y*dx)**2 +((x**2)*dy)**2) |
---|
[2e014bf] | 162 | #if err >= math.fabs(x): |
---|
| 163 | # err =0.9*x |
---|
[831149e] | 164 | return err |
---|
| 165 | |
---|
| 166 | def errToLogXY(x,y,dx=None, dy=None): |
---|
| 167 | """ |
---|
| 168 | calculate error of Log(xy) |
---|
| 169 | """ |
---|
| 170 | if (x!=0) and (y!=0): |
---|
| 171 | if dx == None: |
---|
| 172 | dx = 0 |
---|
| 173 | if dy == None: |
---|
| 174 | dy = 0 |
---|
| 175 | err = (dx/x)**2 + (dy/y)**2 |
---|
[2e014bf] | 176 | #if math.sqrt(math.fabs(err)) >= math.fabs(x): |
---|
| 177 | # err= 0.9*x |
---|
[831149e] | 178 | else: |
---|
| 179 | raise ValueError, "cannot compute this error" |
---|
| 180 | |
---|
| 181 | return math.sqrt(math.fabs(err)) |
---|
| 182 | |
---|
| 183 | def errToLogYX2(x,y,dx=None, dy=None): |
---|
| 184 | """ |
---|
| 185 | calculate error of Log(yx**2) |
---|
| 186 | """ |
---|
| 187 | if (x > 0) and (y > 0): |
---|
| 188 | if (dx == None): |
---|
| 189 | dx = 0 |
---|
| 190 | if (dy == None): |
---|
| 191 | dy = 0 |
---|
[8e44d51] | 192 | err = (2*dx/x)**2 + (dy/y)**2 |
---|
[2e014bf] | 193 | #if math.fabs(err) >= math.fabs(x): |
---|
| 194 | # err =0.9*x |
---|
[831149e] | 195 | else: |
---|
| 196 | raise ValueError, "cannot compute this error" |
---|
| 197 | |
---|
| 198 | return math.sqrt(math.fabs(err)) |
---|
| 199 | |
---|
| 200 | def errOneOverX(x,y=None,dx=None, dy=None): |
---|
| 201 | """ |
---|
| 202 | calculate error on 1/x |
---|
| 203 | """ |
---|
| 204 | if (x != 0): |
---|
| 205 | if dx ==None: |
---|
| 206 | dx= 0 |
---|
| 207 | err = -(dx)**2/x**2 |
---|
| 208 | else: |
---|
| 209 | raise ValueError,"Cannot compute this error" |
---|
| 210 | |
---|
| 211 | if math.fabs(err)>= math.fabs(x): |
---|
| 212 | err= 0.9*x |
---|
| 213 | return math.fabs(err) |
---|
| 214 | |
---|
| 215 | def errOneOverSqrtX(x,y=None, dx=None,dy=None): |
---|
| 216 | """ |
---|
| 217 | Calculate error on 1/sqrt(x) |
---|
| 218 | """ |
---|
| 219 | if (x >0): |
---|
| 220 | if dx==None: |
---|
| 221 | dx =0 |
---|
| 222 | err= -1/2*math.pow(x, -3/2)* dx |
---|
[2e014bf] | 223 | #if math.fabs(err)>= math.fabs(x): |
---|
| 224 | # err=0.9*x |
---|
[831149e] | 225 | else: |
---|
| 226 | raise ValueError, "Cannot compute this error" |
---|
| 227 | |
---|
| 228 | return math.fabs(err) |
---|
[8e44d51] | 229 | def errToLogYX4(x,y=None,dx=None,dy=None): |
---|
| 230 | """ |
---|
| 231 | error for ln(y*x^(4)) |
---|
| 232 | @param x: float value |
---|
| 233 | """ |
---|
| 234 | if dx==None: |
---|
| 235 | dx=0 |
---|
| 236 | if dy==None: |
---|
| 237 | dy=0 |
---|
| 238 | err =math.sqrt((4*dx/x)**2 +(dy/y)**2) |
---|
[2e014bf] | 239 | #if err >= math.fabs(x): |
---|
| 240 | #err =0.9*x |
---|
[8e44d51] | 241 | return err |
---|
[831149e] | 242 | |
---|
| 243 | |
---|