Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 1137
from sympy import * from sympy import N as Num from mpmath import degrees, radians # SI units: m = Symbol("m", positive=True) s = Symbol("s", positive=True) kg = Symbol("kg", positive=True) print("\n--- User input -----------------------") # Derived units: N = kg*m/s/s # quantity = factor times unit: alpha = radians(40) F1 = 6 * N F2 = 8 * N beta = var("beta") n_sig = 3 print("\n--- a: -------------------------------") ca = cos(alpha) sa = sin(alpha) cb = cos(beta) sb = sin(beta) F1_v = F1 * ca F1_h = F1 * sa F2_v = F2 * cb F2_h = F2 * sb for F in [F1_v, F1_h, F2_v, F2_h]: pprint(F / N) print("\n--- b: -------------------------------") # overwrite beta: beta = acos(ca*F1/F2) beta_deg= degrees(beta) pprint(Num(beta_deg,3)) print("\n--- c: -------------------------------") # now with known beta: cb = cos(beta) sb = sin(beta) F2_v = F2 * cb F2_h = F2 * sb R_h = F1_h + F2_h # must be zero: R_v = F1_v - F2_v R = Matrix([R_h, R_v]) pprint(R/N) pprint(Num(R.norm()/N,3))
--- User input ----------------------- --- a: ------------------------------- 4.59626665871387 3.85672565811924 8*cos(beta) 8*sin(beta) --- b: ------------------------------- 54.9 --- c: ------------------------------- [10.404575137299] [ ] [ 0 ] 10.4