Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 588
from sympy import * from sympy import N as Num # pie is better than pi pie = 2*pi # SI units: m = Symbol("m", positive=True) s = Symbol("s", positive=True) kg = Symbol("kg", positive=True) print("\n--- User input -----------------------") one = S(1) half = S(1)/2 fourth = half*half # symbols: R, M, w = var("R, M, omega") w = var("omega") t = var("t") # quantities: quants = [ (R, half *m), (M, one *kg), (w, pie /s), (t, fourth *s) ] # Derived unit: # Newton: N = kg*m/s/s print("\n--- a: -------------------------------") pprint("phi:") def phi(w,t): """phi = omega t""" return w * t print("--- t ---") pprint(phi(w,t)) print("--- t = 1/4 s ---") phi_4 = phi(w,t).subs(quants) pprint(phi_4) print("\n--- b: -------------------------------") pprint("xP, yP:") x = R*cos(phi(w,t)) y = R*sin(phi(w,t)) print("--- t ---") pprint(Matrix([ x, y ])) print("--- t = 1/4 s ---") x_4 = Num(x.subs(quants),3) y_4 = Num(y.subs(quants),3) pprint(Matrix([ x_4, y_4 ])) print("\n--- c: -------------------------------") pprint("vxP, vyP:") vx = diff(x,t) vy = diff(y,t) print("--- t ---") pprint(Matrix([ vx, vy ])) print("--- t = 1/4 s ---") vx_4 = Num(vx.subs(quants),3) vy_4 = Num(vy.subs(quants),3) pprint(Matrix([ vx_4, vy_4 ])) print("\n--- d: -------------------------------") pprint("axP, ayP:") ax = diff(vx,t) ay = diff(vy,t) print("--- t ---") pprint(Matrix([ ax, ay ])) print("--- t = 1/4 s ---") ax_4 = Num(ax.subs(quants),3) ay_4 = Num(ay.subs(quants),3) pprint(Matrix([ ax_4, ay_4 ])) print("\n--- e: -------------------------------") pprint("vxP, vyP:") vr = 0 vp = R*w print("--- t ---") pprint(Matrix([ vr, vp ])) print("--- t = 1/4 s ---") vr_4 = Num(0,3) vp_4 = Num(vp.subs(quants),3) pprint(Matrix([ vr_4, vp_4 ])) print("\n--- f: -------------------------------") pprint("axP, ayP:") ar = - R*w*w ap = 0 print("--- t ---") pprint(Matrix([ ar, ap ])) print("--- t = 1/4 s ---") ar_4 = Num(ar.subs(quants),3) ap_4 = Num(0,3) pprint(Matrix([ ar_4, ap_4 ])) print("\n--- g: -------------------------------") pprint("S:") S = M * R *w*w pprint(S) S_4 = S.subs(quants) # S in Newton: pprint(Num(S_4/N,3))
--- User input ----------------------- --- a: ------------------------------- phi: --- t --- omega*t --- t = 1/4 s --- pi -- 2 --- b: ------------------------------- xP, yP: --- t --- [R*cos(omega*t)] [ ] [R*sin(omega*t)] --- t = 1/4 s --- [ 0 ] [ ] [0.5*m] --- c: ------------------------------- vxP, vyP: --- t --- [-R*omega*sin(omega*t)] [ ] [R*omega*cos(omega*t) ] --- t = 1/4 s --- [-3.14*m ] [--------] [ s ] [ ] [ 0 ] --- d: ------------------------------- axP, ayP: --- t --- [ 2 ] [-R*omega *cos(omega*t)] [ ] [ 2 ] [-R*omega *sin(omega*t)] --- t = 1/4 s --- [ 0 ] [ ] [-19.7*m ] [--------] [ 2 ] [ s ] --- e: ------------------------------- vxP, vyP: --- t --- [ 0 ] [ ] [R*omega] --- t = 1/4 s --- [ 0 ] [ ] [3.14*m] [------] [ s ] --- f: ------------------------------- axP, ayP: --- t --- [ 2] [-R*omega ] [ ] [ 0 ] --- t = 1/4 s --- [-19.7*m ] [--------] [ 2 ] [ s ] [ ] [ 0 ] --- g: ------------------------------- S: 2 M*R*omega 19.7