DaZyS
Newbie
Offline
Posts: 14
|
 |
«
Embed this message
on: October 01, 2010, 06:57:04 pm » posted from:Cornellá,Catalonia,Spain |
|
 Hello friends, I have a problem, I make a sine wave with "A*Math.sin(2*Math.PI*fr*t);", but I don't know how to do a triangle wave. Anyone can help me? thanks! Sorry for me English.
|
|
|
Logged
|
|
|
|
Fu-Kwun Hwang
|
 |
«
Embed this message
Reply #1 on: October 01, 2010, 10:54:35 pm » posted from:,,Taiwan |
|
 A triangle wave can be generated from sum of many sinwave. Please check out Fourier Synthesis
|
|
|
Logged
|
|
|
|
DaZyS
Newbie
Offline
Posts: 14
|
 |
«
Embed this message
Reply #2 on: October 02, 2010, 01:56:12 am » posted from:Cornellá,Catalonia,Spain |
|
 I'm noob in EJS. There is no other way to make a triangle wave? Thanks.
|
|
|
Logged
|
|
|
|
Fu-Kwun Hwang
|
 |
«
Embed this message
Reply #3 on: October 02, 2010, 02:17:15 am » posted from:,,Taiwan |
|
 There are several ways to generate a triangle wave in EJS. I would suggest you draw a triangle wave in a piece of paper. Then draw similar segments with java code. If you want to do it in EJS: You can define x,y array to represent (x,y) coordinate for triangle wave. Use a loop to assign correct value for triangle wave (several segment of line) then assign x,y to polygon GUI element to draw it.
|
|
|
Logged
|
|
|
|
DaZyS
Newbie
Offline
Posts: 14
|
 |
«
Embed this message
Reply #4 on: October 02, 2010, 03:28:06 am » posted from:Cornellá,Catalonia,Spain |
|
 I'm very lost, thanks anyway.
|
|
|
Logged
|
|
|
|
Fu-Kwun Hwang
|
 |
«
Embed this message
Reply #5 on: October 02, 2010, 09:28:51 am » posted from:,,Taiwan |
|
 I hope the following is what you are looking for. Embed a running copy of this simulation Embed a running copy link(show simulation in a popuped window) Full screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site listPress the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
- Please feel free to post your ideas about how to use the simulation for better teaching and learning.
- Post questions to be asked to help students to think, to explore.
- Upload worksheets as attached files to share with more users.
Let's work together. We can help more users understand physics conceptually and enjoy the fun of learning physics!
 
|
|
|
Logged
|
|
|
|
DaZyS
Newbie
Offline
Posts: 14
|
 |
«
Embed this message
Reply #6 on: October 02, 2010, 05:47:22 pm » posted from:Barcelona,Catalonia,Spain |
|
 Thank you very much for your time, that is the triangular wave I want to create, but in my simulation, I have x = t and y = i = sin(t), the graph is a trace, in their simulation is a polygon where x = x, y = y. I'm sending you my EJS's file, could you look it? Thank you. I'm studying their simulation.
|
*** There are 1 more attached files. You need to login to acces it!
|
|
Logged
|
|
|
|
Fu-Kwun Hwang
|
 |
«
Embed this message
Reply #7 on: October 02, 2010, 08:36:25 pm » posted from:,,Taiwan |
|
 There are too many file. I do not know which one to look for. You can use trace GUI element to add one point at a time for each time step. However, you can use polygon GUI elements to draw pre-defined number of connected points. You just need to define x,y as array with n elements in EJS variable page. then assign (x ,y) with a for loop in EJS "fixed relation" page. Add ploygin GUI element under drawingPanel2D, assign x,y as "x/y data" proper, and EJS will show the polygons when you run it.
The following code is added at initialize page
k=2*pi/L; w=2*pi/T; for(int i=0;i<n;i++){ x[i]=i*dx; }
And the following code is added at fixed relation page for(int i=0;i<n;i++){ cta=(k*x[i]+w*t)%pi2; if(cta>pi)y[i]=A*(1-(cta-pi)/pi); else y[i]=cta/pi*A; }
|
|
|
Logged
|
|
|
|
DaZyS
Newbie
Offline
Posts: 14
|
 |
«
Embed this message
Reply #8 on: October 05, 2010, 05:45:57 pm » posted from:Barcelona,Catalonia,Spain |
|
 Hello gentleman Fu-Kwun Hwang, I send my EJS's source code,you will see my low level in java. For me it is very difficult to understand his triangular wave. You could help put the triangular wave in my project? Thanks for your time.
|
*** There are 1 more attached files. You need to login to acces it!
|
|
Logged
|
|
|
|
|
DaZyS
Newbie
Offline
Posts: 14
|
 |
«
Embed this message
Reply #10 on: October 05, 2010, 10:33:41 pm » posted from:Barcelona,Catalonia,Spain |
|
 Thanks for the simulation! I have to study the triangular wave, because I don't understand the parameters. Thanks for you time!
|
|
|
Logged
|
|
|
|
Fu-Kwun Hwang
|
 |
«
Embed this message
Reply #11 on: October 05, 2010, 10:48:31 pm » posted from:,,Taiwan |
|
 I downloaded your Actual Memristor.ejs file and compiled it with EJS. But I can not figure out what you were doing and what kind of help you need. Please describe in detail what you want to do and how can we help! Check out the previous example if you just need to make a triangle wave. y=f(x,t) increasing when (t%T) < T/2 and decreasing when (t%T)>T/2
|
|
|
Logged
|
|
|
|
DaZyS
Newbie
Offline
Posts: 14
|
 |
«
Embed this message
Reply #12 on: October 06, 2010, 10:19:42 pm » posted from:Barcelona,Catalonia,Spain |
|
 Hello sir, I have a problem with her simulation. I need to know how to modify the wave. I put a picture.  The first image is the wave that I want do. The second is her simulation.
|
|
|
Logged
|
|
|
|
Fu-Kwun Hwang
|
 |
«
Embed this message
Reply #13 on: October 06, 2010, 11:56:11 pm » posted from:,,Taiwan |
|
 You need to provide relation between x,y coordinates to tell EJS or any program to draw it. You can treat the lsft image as segment of three different lines. A line can be represented by y=m*x +b Try to find out those three equations for three drifferent segments.
|
|
|
Logged
|
|
|
|
DaZyS
Newbie
Offline
Posts: 14
|
 |
«
Embed this message
Reply #14 on: October 08, 2010, 03:05:02 am » posted from:Barcelona,Catalonia,Spain |
|
 Thanks to Fu-Kwun Hwang and lookang !!! Triangular wave is here!! the code is: if(triangularWave) { for(int i=0;i<n;i++){
cta=(x+w*t)%pi2;
if (cta<(pi/2)) y=2*cta/pi*A; else y=2*A*(1-(cta-pi)/pi)-A*2; if (cta>pi) y=2*A*(1-(cta-pi)/pi)-2*A; if (cta>(3*pi/2)) y=-2*A*(1-(cta-pi)/pi);
return y; } 
|
|
« Last Edit: October 08, 2010, 03:07:34 am by DaZyS »
|
Logged
|
|
|
|
Fu-Kwun Hwang
|
 |
«
Embed this message
Reply #15 on: October 08, 2010, 03:22:35 pm » posted from:Taipei,T'ai-pei,Taiwan |
|
 Great! you make it by yourself. It is also possible to do it with just one pair of (if and else) code. Just shift the origin of your coordinate system. I will leave it as an exercise for you! 
|
|
|
Logged
|
|
|
|
|