phystricks
|
Classes | |
class | CalculSage |
class | Fichier |
Functions | |
def | MultipleBetween (Dx, mx, Mx, mark_origin=True) |
def | SubGridArray (mx, Mx, Dx, num_subX) |
def | MainGridArray (mx, Mx, Dx) |
def | RemoveLastZeros (x, n) |
def | number_at_position (s, n) |
def | get_line (s, pos) |
def | string_number_comparison (s1, s2, epsilon=0.01, last_justification="") |
def | around (x, decimals) |
def | MultipleLower (x, m) |
def | MultipleBigger (x, m) |
def | visualPolarCoordinates (r, theta, xunit=1, yunit=1) |
def | split_list (starting_list, fun, cut_ymin, cut_ymax) |
def | find_roots_recursive (f, a, b, tol=0.000000000001) |
def phystricks.src.SmallComputations.around | ( | x, | |
decimals | |||
) |
return `x` truncated after a certain number of decimals. INPUT: - ``x`` - a number - ``deciamsl`` - integer OUTPUT: A number. EXAMPLES:: sage: from phystricks.SmallComputations import * sage: around(100.6867867,3) 100.687
def phystricks.src.SmallComputations.find_roots_recursive | ( | f, | |
a, | |||
b, | |||
tol = 0.000000000001 |
|||
) |
Return the roots of the function 'f' between 'a' and 'b' as a list. We assume two roots are always separated by more than `tol`. The list is sorted.
def phystricks.src.SmallComputations.get_line | ( | s, | |
pos | |||
) |
def phystricks.src.SmallComputations.MainGridArray | ( | mx, | |
Mx, | |||
Dx | |||
) |
Return the list of number that are 1. integer multiple of Dx 2. between mx and Mx If mx=-1.4 and Dx=0.5, the first element of the list will be -1 If mx=-1.5 and Dx=0.5, the first element of the list will be -1.5 If mx=0 and Dx=1, the first element of the list will be 0.
def phystricks.src.SmallComputations.MultipleBetween | ( | Dx, | |
mx, | |||
Mx, | |||
mark_origin = True |
|||
) |
Return the list of values that are all the integer multiple of Dx between mx and Mx. If <mark_origin> is True, the list includes 0 if applicable.
def phystricks.src.SmallComputations.MultipleBigger | ( | x, | |
m | |||
) |
Return the lower multiple of m which is bigger or equal to x EXAMPLES :: sage: from phystricks.SmallComputations import * sage: MultipleBigger(11.0,2) 12
def phystricks.src.SmallComputations.MultipleLower | ( | x, | |
m | |||
) |
return the biggest multiple of m which is lower or equal to x
def phystricks.src.SmallComputations.number_at_position | ( | s, | |
n | |||
) |
return the number being at position `n` in `s` as well as the first and last positions of that number in `s`. Return False is the position `n` is not part of a number. INPUT: - ``s`` - a string. - ``n`` - a number. OUTPUT: a tuple (string,integer,integer) EXAMPLES: sage: from phystricks.SmallComputations import * sage: s="Point(-1.3427,0.1223)" sage: number_at_position(s,9) ('-1.3427', 6, 13) sage: number_at_position(s,6) ('-1.3427', 6, 13) sage: number_at_position(s,3) (False, 0, 0) sage: s="\\begin{pspicture}(-0.375000000000000,-1.94848632812500)(3.00000000000000,1.94860839843750)" sage: number_at_position(s,20) ('-0.375000000000000', 18, 36) sage: number_at_position(s,27) ('-0.375000000000000', 18, 36) sage: number_at_position(s,60) ('3.00000000000000', 56, 72) sage: number_at_position(s,80) ('1.94860839843750', 73, 89) That allows to make cool replacements. In the following, we replace the occurrence of "0.12124" that is on position 4:: sage: s="Ps=0.12124 and Qs=0.12124" sage: v,first,last=number_at_position(s,4) sage: print s[:first]+"AAA"+s[last:] Ps=AAA and Qs=0.12124 NOTE: We cannot return the number since the aim is to substitute it *as string* in the function :func:`string_number_comparison`. The problem in returning a number is the following:: sage: SR(str('1.94848632812500')) 1.94848632812
def phystricks.src.SmallComputations.RemoveLastZeros | ( | x, | |
n | |||
) |
Cut the number `x` to n decimals and then remove the last zeros. If there remain no decimals, also remove the dot. We only cut a given number of decimals; if the integer part has more digits, we keep them. The output is a string, not a number. INPUT: - ``x`` - a number. - ``n`` - the number of decimals we want to keep. OUTPUT: A string. EXAMPLES:: sage: from phystricks.SmallComputations import * sage: RemoveLastZeros(1.000,4) '1' sage: RemoveLastZeros(3/4,1) '0.7' sage: RemoveLastZeros(3/4,3) '0.75' sage: RemoveLastZeros(3/4,4) '0.75' sage: RemoveLastZeros(pi,4) '3.1415' sage: RemoveLastZeros(130*e,2) '353.37' NOTE : Part of the algorithm comes from http://www.java2s.com/Code/Python/Development/StringformatFivedigitsafterdecimalinfloat.htm
def phystricks.src.SmallComputations.split_list | ( | starting_list, | |
fun, | |||
cut_ymin, | |||
cut_ymax | |||
) |
def phystricks.src.SmallComputations.string_number_comparison | ( | s1, | |
s2, | |||
epsilon = 0.01 , |
|||
last_justification = "" |
|||
) |
def phystricks.src.SmallComputations.SubGridArray | ( | mx, | |
Mx, | |||
Dx, | |||
num_subX | |||
) |
Provides the values between mx and Mx such that there are num_subX-1 numbers between two integer separated by Dx
def phystricks.src.SmallComputations.visualPolarCoordinates | ( | r, | |
theta, | |||
xunit = 1 , |
|||
yunit = 1 |
|||
) |
return the polar coordinated that you have to give in such a way the it *visually* appears `(r,theta)` when `xunit` and `yunit` are given. The input and output angles are in radian. INPUT: - ``r`` - the distance you want to see. - ``theta`` - the angle you want to see (radian or AngleMeasure). If the angle is passed as 'AngleMeasure', the answer will also be AngleMeasure - ``xunit`` - the dilatation factor in the `x` direction. - ``yunit`` - the dilatation factor in the `y` direction. OUTPUT: a tuple `(distance,angle)` EXAMPLES:: sage: from phystricks.SmallComputations import * sage: polar_with_dilatation(2,pi,2,1) (1, pi) sage: polar_with_dilatation(1,pi/4,2,2) (1/2, 1/4*pi) Notice the difference between:: sage: polar_with_dilatation(1,pi/2,2,1/2) (2, 1/2*pi) and:: sage: polar_with_dilatation(1,pi/2,2,0.5) (2.00000000000000, 1/2*pi)