Demo entry 5685591

Code de la simulation

   

Submitted by anonymous on Jul 08, 2016 at 19:36
Language: Python 3. Code size: 1.2 kB.

from numpy import *
from matplotlib import pyplot as plt

def multiple_osci(tf,origine1,origine2,epsilon,points):

	g	= 9.81
	Mbase	= 0.04
	m1	= 0.01
	m2	= 0.00464
	r1	= 0.025
	r2	= 0.04
	th0	= 0.4363325
	I	= m1*(r1**2)+m2*(r2**2)
	RM	= (m1*r1+m2*r2)
	M	= m1 + m2

	Gamma	= RM/I
	Omega2	= g*Gamma
	Beta	= (RM**2)/(I*(Mbase+(2*M)))

	pas	= tf/points

	f	= lambda x,x1,D		: (epsilon*x1*(1-((x/th0)**2)))-(Omega2*sin(x))-(cos(x)*D)
	dx2	= lambda t,t1,t2,s,s1,s2: -Beta*((t2*cos(t))-((t1**2)*sin(t))+(s2*cos(s))-((s1**2)*sin(s)))

	I	= [i*pas for i in range(points)]

	S	= [origine2]
	S1	= [0]
	S2	= [f(origine2,0,0)]

	TH	= [origine1]
	TH1	= [0]
	TH2	= [f(origine1,0,0)]

	X       = [dx2(0,0,TH2[-1],0,0,S2[-1])]

	for i in range(1,points):

		t,t1,t2 = TH[-1],TH1[-1],TH2[-1]
		s,s1,s2 = S[-1],S1[-1],S2[-1]

		x = X[-1]
		
		t  += pas*t1
		t1 += pas*t2
		t2 = f(t,t1,x)

		s  += pas*s1
		s1 += pas*s2
		s2 = f(s,s1,x)
		
		X.append(dx2(t,t1,t2,s,s1,s2))

		TH.append(t)
		TH1.append(t1)
		TH2.append(t2)

		S.append(s)
		S1.append(s1)
		S2.append(s2)

	plt.plot(I,TH)
	plt.plot(I,S)

	return(TH[-1],S[-1])

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).