예제 #1
0
def make_matrices(a, b, c, d, e, f):
    A = [a, b, d, e]
    B = [["x"], ["y"]]
    C = [[c], [f]]
    return A, B, C

def multiply(iA, C):
    return [
        (iA[0]*C[0][0])+(iA[1]*C[1][0]),
        (iA[2]*C[0][0])+(iA[3]*C[1][0])
    ]


if __name__ == "__main__":
    from util import get_vars

    print("ax + by = c\ndx + ey = f")
    vars = get_vars({
        "a":float,
        "b":float,
        "c":float,
        "d":float,
        "e":float,
        "f":float
    })

    A, B, C = make_matrices(**vars)
    iA = inverse_matrix(*A)
    ans = multiply(iA, C)
    print(f"x= {ans[0]}\ny= {ans[1]}")
예제 #2
0
|   | Horizontal | Vertical |
| - | ---------- | -------- |
| Equation | `( (x - h)^2 / a^2 ) - ( (y - k)^2 / b^2 ) = 1` | `( (y - k)^2 / a^2 ) - ( (x - h)^2 / b^2 ) = 1 ` |
| Center | `(h, k)` | `(h, k)` |
| Foci | `(h - c, k)` and `(h + c, k)` | `(h, k - c)` and `(h, k + c)` |
| Vertices | `(h - a, k)` and `(h + a, k)` | `(h, k - a)` and `(h, k + a)` |
| Slopes of Asymptotes | `b / a` and `-b / a` | `a / b` and `-a / b`

"""
__doc__ = doc


class Hyperbola():
    __doc__ = doc

    def __init__(self):
        self.name = name

    def hi(self, greeting="Hello, ", puctuation="!"):
        return greeting + self.name + puctuation


def main(a, b, c):
    pass


if __name__ == '__main__':
    from util import get_vars
    main(**get_vars({}))
예제 #3
0
#!/usr/bin/env python3
# name_of_file.py
"""
An explanation of the concept/formula.
Each part and it's function:

a + b = b + a
# check_abba(a, b) -> bool
"""

# import other math concepts
# from determiants import determiant2


def check_abba(a, b):
    return (a + b) == (b + a)


if __name__ == "__main__":
    from util import get_vars

    print("a + b = b + a")
    vars = get_vars({"a": float, "b": float})

    print(check_abba(**vars))
예제 #4
0
파일: slope.py 프로젝트: coderkearns/school
# checkslope(x1, y1, x2, y2) -> [float or None or False]
# slope(x1, y1, x2, y2) -> float
"""


def checkslope(x1, y1, x2, y2):
    if x1 == x2:
        return None
    if y1 == y2:
        return 0
    return True


def slope(x1, y1, x2, y2):
    check = checkslope(x1, y1, x2, y2)
    if check != True:
        return check
    rise = y2 - y1
    run = x2 - x1
    return rise / run


if __name__ == "__main__":
    from util import get_vars

    print("m = (y2-y1) / (x2-x1)")
    vars = get_vars({"x1": float, "y1": float, "x2": float, "y2": float})

    print(slope(**vars))
예제 #5
0
# determiant2(a,b,c,d) -> float
"""


def determiant2(a, b, c, d):
    return ((a * d) - (b * c))


def determiant3(a, b, c, d, e, f, g, h, i):
    return ((a * e * i) + (b * f * g) + (c * d * h) - (g * e * c) -
            (h * f * a) - (i * d * b))


if __name__ == "__main__":
    from util import get_vars

    print("|a b c, d e f, g h i| =\naei + bfg + cdb - gec - kfa - idb")
    vars = get_vars({
        "a": float,
        "b": float,
        "c": float,
        "d": float,
        "e": float,
        "f": float,
        "g": float,
        "h": float,
        "i": float,
    })

    print(determiant3(**vars))
예제 #6
0
        if d == 0: return Parabola
        if d > 0: return Hyperbola
        if d < 0:
            if (self.B == 0 and self.A == self.C): return Circle
            if (self.B != 0): return Ellipse
            if (self.A != 0 and self.C != 0 and self.A != self.C):
                return Ellipse

        raise ConicSectionException(
            "Not a Parabola, Hyperbola, Circle, or Ellipse")


def main(A, B, C, D, E, F):
    conic_section = ConicSection(A, B, C, D, E, F)
    print(conic_section.type.__name__)


if __name__ == '__main__':
    from util import get_vars

    print("Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0")

    main(**get_vars({
        "A": float,
        "B": float,
        "C": float,
        "D": float,
        "E": float,
        "F": float,
    }))
        data.append(f"{row}{spaces} | {y}")
        row += 1
    print(x_name + " | " + y_name)
    print("-" * (x + 1) + "|" + "-" * (len(y_name) + 1))
    print("\n".join(data))
    return data


def format_ans(func, los, vertex, y_intercept, abc):
    func, los, vertex, y_intercept = map(str, [func, los, vertex, y_intercept])
    return "\n".join([
        "y = " + func, "", "line of symetry: " + los, "vertex: " + vertex,
        "y-intercept: " + y_intercept, "",
        "direction: " + ("up" if abc[0] > 0 else "down"),
        "vertex type: " + ("minimum" if abc[0] > 0 else "maximum")
    ])


if __name__ == "__main__":
    from util import get_vars

    print("ax^2 + bx + c")
    vars = get_vars({"a": float, "b": float, "c": float, "x": str, "y": str})

    print()
    f, func, l, v, y, abc = solve_problem_with_quadratics(**vars)
    print(format_ans(func, l, v, y, abc))
    print()
    data = create_table(f, vars["x"], vars["y"], 10)
    plot(f, v, data, vars["x"], vars["y"])
예제 #8
0

def y_intercept(a, h, k):
    return (a * (0.0 - h)**2 + k)


def vertex_form(a, h, k):
    func = format_func(a, h, k)

    los = h
    v = vertex(h, k)
    y = y_intercept(a, h, k)

    los, y = strip_all(los, y)
    los, v, y = map(str, (los, v, y))

    return "\n".join([
        func, "", "line of symmetry = " + los, "vertex = " + v,
        "y-intercept = " + y
    ])


if __name__ == "__main__":
    from util import get_vars

    print("y = a(x-h)^2 + k")
    vars = get_vars({"a": float, "h": float, "k": float})

    print()
    print(vertex_form(**vars))
예제 #9
0
def condition_one(a, b, c, d):
    return determiant2(a, b, c, d) != 0


def inverse_matrix(a, b, c, d):
    if not condition_one(a, b, c, d): quit("|a b, c d| == 0, none")
    multiplier = (1 / determiant2(a, b, c, d))
    a *= multiplier
    b *= multiplier
    c *= multiplier
    d *= multiplier
    return (d, -1 * (b), -1 * (c), a)


def print_matrix(a, b, c, d):
    print(f"[{a}  {b}]\n[{c}  {d}]")


if __name__ == "__main__":
    from util import get_vars

    print("A = [a b]\n    [c d]")
    vars = get_vars({
        "a": float,
        "b": float,
        "c": float,
        "d": float,
    })

    print_matrix(*inverse_matrix(**vars))
예제 #10
0

def sort_ans(a, b):
    if a["area"] < b["area"]:
        return 1
    elif a["area"] == b["area"]:
        return 0
    else:
        return -1


def maximum_area_of_rectangle(P, r=100, unit="cm"):
    answers = []
    for l in range(-1 * r, r):
        for w in range(-1 * r, r):
            if (l + l + w + w) == P:
                answers.append({"area": l * w, "l": l, "w": w})

    answers.sort(key=cmp_to_key(sort_ans))
    max_area, l, w = answers[0].values()
    return f"dims= ({l}{unit} by {w}{unit}), area= {max_area}{unit}²"


if __name__ == "__main__":
    from util import get_vars

    print("P = Perimeter")
    vars = get_vars({"P": float})

    print(maximum_area_of_rectangle(**vars))
예제 #11
0
    x = ans_x(*vars.values(), d)
    y = ans_y(*vars.values(), d)
    z = ans_z(*vars.values(), d)


if __name__ == "__main__":
    from util import get_vars

    print("a1x + b1y + c1z = d1\na2x + b2y + c2z = d2\na3x + b3y + c3z = d3")
    vars = get_vars({
        "a1": float,
        "b1": float,
        "c1": float,
        "d1": float,
        "a2": float,
        "b2": float,
        "c2": float,
        "d2": float,
        "a3": float,
        "b3": float,
        "c3": float,
        "d3": float,
    })

    d = determiant3(vars["a1"], vars["b1"], vars["c1"], vars["a2"], vars["b2"],
                    vars["c2"], vars["a3"], vars["b3"], vars["c3"])

    x = ans_x(*vars.values(), d)
    y = ans_y(*vars.values(), d)
    z = ans_z(*vars.values(), d)

    print()
예제 #12
0
            return f"""
            (x - {self.h})^2    (y - {self.k})^2
            —————————— + —————————— = 1
               {self.b**2}          {self.a**2}
            """


    def __repr__(self):
        print(self.equation)
        return f"{self.__class__.__name__}(a={self.a}, b={self.b}, c={self.c}, h={self.h}, k={self.k})"


def main(h, k, a, b):
    c = sympy.sqrt(a - b)
    if b > a:
        print(f"({strip_float(h)}, {strip_float(k+c)})")
        print(f"({strip_float(h)}, {strip_float(k-c)})")
    else:
        print(f"({strip_float(h+c)}, {strip_float(k)})")
        print(f"({strip_float(h-c)}, {strip_float(k)})")


if __name__ == '__main__':
    from util import get_vars
    main(**get_vars({
        "h": float,
        "k": float,
        "a": float,
        "b": float
    }))
예제 #13
0
파일: itk.py 프로젝트: coderkearns/school
t(b) = boil_after_change - old_boil
t(f) = freeze_after_change - old_freeze

"""

def calc_mw(temp_after_change, old_temp, k, mass, kg, i):
    t = temp_after_change - old_temp
    return i * k * ( (mass / t) / kg )



if __name__ == "__main__":
    from util import get_vars

    print("MW = i * ( ( mass / t ) / kg ) * k")
    print("t(b) = boil_after_change - old_boil")
    print("t(f) = freeze_after_change - old_freeze")
    print("k = k(b) or k(f), depending on  what was used in t")

    vars = get_vars({
        "temp_after_change":float,
        "old_temp":float,
        "k":float,
        "mass":float,
        "kg":float,
        "i":float
    })

    print(calc_mw(**vars))
예제 #14
0
                mol(m, w),  # mols
                v  # liters
            ))


if __name__ == "__main__":
    from util import get_vars, alias

    print("Π = MRT")
    print("Π = ((mass/mw)/v)RT")
    print_R()
    print("")

    vars = get_vars({
        "mass": float,
        "mw": float,
        "volume": float,
        "temp (C)": float,
        "pressure type": str
    })

    print(
        osmotic_pressure(**alias(
            vars, {
                "mass": "m",
                "mw": "w",
                "volume": "v",
                "temp (C)": "t",
                "pressure type": "pressure_unit"
            })))