By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 428,601 Members | 989 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

# problem based upon coupled oscillatorcoupled oscillator

 P: 1 i have written program for coupled oscillator(numerical solution)using euler method. but i am not getting the exact graph.can somebdy help me out of it. Expand|Select|Wrap|Line Numbers K=2 g=9.8 L=8 m=2.0 Tm=10 N=125 h=Tm/float(N) import matplotlib.pyplot as plt import numpy as np import numpy as n1 x1=n1.zeros(N+1) x2=np.zeros(N+1) v1=n1.zeros(N+1) v2=np.zeros(N+1) t=np.zeros(N+1) x1=10 x2=0 v1=0 v2=0 i=0 while t[i]
Share this Question
1 Reply

 Expert 100+ P: 616 but i am not getting the exact graph What does this mean. If you are using Python2.x then you should explicitly cast a divide operation to a float, otherwise it is possible to get an integer only as a result. Expand|Select|Wrap|Line Numbers ## -g/float(L) v1[i+1]=(-g/float(L))*x1[i] - (K/m)*(x1[i]-x2[i]  Also it is possible in the while t[i] statement for "i" to exceed the length of N+1 so you should test for that. Finally, do not use i,l, O, etc as single digit variable names as they look too much like numbers, and to make your code readable by others, take a look at the Python Style Guide, which suggests lower case with underlines for variable names.. An alternative to the while statement (logic only), although there is nothing wrong with the while statement Expand|Select|Wrap|Line Numbers def check_t(t, Tm, N):     for ctr in range(N+1):         if t[ctr] >= Tm:             return         ## do the calcs        ##raise error as t[ctr] >= Tm was never hit Aug 15 '14 #2

### Post your reply

Sign in to post your reply or Sign up for a free account. 