473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem based upon coupled oscillatorcoupled oscillator

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
  1. K=2
  2. g=9.8
  3. L=8
  4. m=2.0
  5. Tm=10
  6. N=125
  7. h=Tm/float(N)
  8. import matplotlib.pyplot as plt
  9. import numpy as np
  10. import numpy as n1
  11. x1=n1.zeros(N+1)
  12. x2=np.zeros(N+1)
  13. v1=n1.zeros(N+1)
  14. v2=np.zeros(N+1)
  15. t=np.zeros(N+1)
  16. x1[0]=10
  17. x2[0]=0
  18. v1[0]=0
  19. v2[0]=0
  20. i=0
  21. while t[i]<Tm:
  22.     v1[i+1]=(-g/L)*x1[i] - (K/m)*(x1[i]-x2[i])
  23.     v2[i+1]=(-g/L)*x2[i] - (K/m)*(x2[i]-x1[i])
  24.     x1[i+1]=x1[i] + v1[i+1]*h
  25.     x2[i+1]=x2[i] + v2[i+1]*h
  26.     t[i+1]=t[i]+h
  27.     i=i+1
  28. plt.subplot(211)
  29. plt.plot(t,x1)
  30. plt.subplot(212)
  31. plt.plot(t,x2)
  32. plt.show()
Aug 15 '14 #1
1 1220
dwblas
626 Expert 512MB
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
  1. ## -g/float(L)
  2. 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
  1. def check_t(t, Tm, N):
  2.     for ctr in range(N+1):
  3.         if t[ctr] >= Tm:
  4.             return
  5.         ## do the calcs 
  6.  
  7.     ##raise error as t[ctr] >= Tm was never hit
Aug 15 '14 #2

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

Similar topics

3
by: Micromanaged | last post by:
Is it possible (and if so, how?) to have an asp form page that based upon a user's selection on a field, would generate a input field b that the user selects? For example: User selects "name"...
2
by: e2biz | last post by:
I want to change the style of a data presented based upon the value of the data. For example, I if the value is positive I want it to appear black but if it is negative I want it to be red. Any...
1
by: Mike P | last post by:
Is it possible when populating a datagrid to populate a dropdownlist column based upon the value populated to another row in the datagrid? (i.e. I have a drop down which I want to populate...
7
by: mike.a.rea | last post by:
Say that I have a form with a drop down list box. This list will set a value for a data field (for lack of a better word) say this is called test1. This is what I have for my basic form. form...
3
by: skinnybloke | last post by:
Hi - I have the following VB function within MS Access which is called via a query. How do I modify this code so that it will only do the replacement based upon the value of another field on the...
2
by: Bob | last post by:
I am developing an ASP.NET application that needs to archive documents and support the retrieval of them. When the document is stored, the user needs to be able to indicate whether it is a public...
1
by: eric1328 | last post by:
Say I have a table in a MS Access database (.mdb), that’s on the web, with two columns: “IP” – these entries would be manually entered with certain IP addresses “Text” I would like a script on a...
3
by: joseph.mccastlain | last post by:
Hello All, I am a new user to Access. I am currently designing a database consisting of four tables for multiple users. Rather than bore you with the goals and such, here is what I am...
0
by: spowel4 | last post by:
VB 2005: Using an xml file as the data source, I need to fill a listbox with data based upon what was selected in a combobox. In other words, my data consists of a list of customers in a...
3
by: ajaypaidi | last post by:
HI gurus, i need to select a value based upon 2 columns.for instance,i have table A and Table B where Table A has 2,3,4,5 values and Table B has D,E,F,G,H,I,J,K L,M which is related to Table A in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.