Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 1137
from sympy.physics.units import * from sympy import * # Given symbols: R, a, b = var("R, alpha, beta", real=true) ta = tan(a) tb = tan(b) # Unknowns: F1x, F1y, F2x, F2y = var("F_{1x}, F_{1y}, F_{2x}, F_{2y}", real=true) unknowns = [F1x, F1y, F2x, F2y] pprint("\n--- a ------------------------------------") pprint("\n--- Symbols-------------------------------") eq1 = Eq(F1x + F2x, 0) eq2 = Eq(F1y + F2y, -R) eq3 = Eq(ta, F1y/F1x) eq4 = Eq(tb, F2y/F2x) eqns = [eq1, eq2, eq3, eq4] sol = solve(eqns, unknowns) (F1x, F1y) = (sol[F1x], sol[F1y]) (F2x, F2y) = (sol[F2x], sol[F2y]) F1 = Matrix([F1x, F1y]) F2 = Matrix([F2x, F2y]) pprint("\nF1:") pprint(F1) # pprint(latex(F1)) pprint("\nF2:") pprint(F2) # pprint(latex(F2)) pprint("\n--- b ------------------------------------") pprint("\n--- Quantities ---------------------------") sublist = { R: S(9)/2*newton, a: 45*pi/180, b: 15*pi/180 } pprint("S1 and S2:") for F in [F1, F2]: F = F.subs(sublist) F /= newton pprint("\nComponents / N:") pprint("\nExact:") pprint(F) # pprint(latex(F)) pprint("\nApprox:") pprint(N(F,2)) # pprint(latex(N(F,2))) pprint("\n--- c ------------------------------------") pprint("\n--- Quantities ---------------------------") for F in [F1, F2]: F = F.subs(sublist) F /= newton pprint("\nNorm = Magnitude / N:") F = F.norm() pprint(N(F,2))
--- a ------------------------------------ --- Symbols------------------------------- F1: [ -R ] [----------------------] [tan(alpha) - tan(beta)] [ ] [ -R*tan(alpha) ] [----------------------] [tan(alpha) - tan(beta)] F2: [ R ] [----------------------] [tan(alpha) - tan(beta)] [ ] [ R*tan(beta) ] [----------------------] [tan(alpha) - tan(beta)] --- b ------------------------------------ --- Quantities --------------------------- S1 and S2: Components / N: Exact: [ -9 ] [--------------] [ / ___\] [2*\-1 + \/ 3 /] [ ] [ -9 ] [--------------] [ / ___\] [2*\-1 + \/ 3 /] Approx: [-6.1] [ ] [-6.1] Components / N: Exact: [ 9 ] [-------------- ] [ / ___\ ] [2*\-1 + \/ 3 / ] [ ] [ / ___ \] [9*\- \/ 3 + 2/] [---------------] [ / ___\] [ 2*\-1 + \/ 3 /] Approx: [6.1] [ ] [1.6] --- c ------------------------------------ --- Quantities ---------------------------- Norm = Magnitude / N: 8.7 Norm = Magnitude / N: 6.4