NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
August 16, 2020, 12:46:01 am
 Welcome, Guest. Please login or register.Did you miss your activation email? 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length

 Home Help Search Login Register
Know the universe as yourself and you can live anywhere in comfort. ...Lao Tzu (570-490 BC)

 Pages: [1]   Go Down
 Author Topic: How to make a triangle wave?  (Read 19897 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
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
Administrator
Hero Member

Offline

Posts: 3085

 « 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
Administrator
Hero Member

Offline

Posts: 3085

 « 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
Administrator
Hero Member

Offline

Posts: 3085

 « 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 list
Press 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
Administrator
Hero Member

Offline

Posts: 3085

 « 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
Code:
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
Code:
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
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message Reply #9 on: October 05, 2010, 09:02:17 pm »

i help u

do post up your applet here at NTNUJAVA Virtual Physics Laboratory say http://www.phy.ntnu.edu.tw/ntnujava/index.php?board=28.0 or any relevant board?
your applet looks like an electronic topic maybe http://www.phy.ntnu.edu.tw/ntnujava/index.php?board=16.0

do share your work (applet and worksheets etc) here! we are nurturing a learning community of Ejs users.
 *** There are 1 more attached files. You need to login to acces it! « Last Edit: October 05, 2010, 09:09:21 pm by lookang » 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
Administrator
Hero Member

Offline

Posts: 3085

 « 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
Administrator
Hero Member

Offline

Posts: 3085

 « 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:

Quote
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
Administrator
Hero Member

Offline

Posts: 3085

 « 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
 Pages: [1]   Go Up
Know the universe as yourself and you can live anywhere in comfort. ...Lao Tzu (570-490 BC)
Jump to:

 Related Topics Subject Started by Replies Views Last post Intensity of reflected s-wave/p-wave Optics Fu-Kwun Hwang 2 40233 October 16, 2007, 04:37:51 pm by Fu-Kwun Hwang how to make the text b always appear after the simulation is reset? Dynamics lookang 16 18557 July 26, 2007, 11:40:25 pm by Fu-Kwun Hwang is it possible to make applet make a sound when i condition is met? Questions related to EJS lookang 8 12447 December 22, 2008, 12:10:01 pm by lookang how to make a differentiation of a string? Questions related to EJS lookang 5 9146 January 30, 2009, 02:29:12 am by lookang how to make the vectorField2D appears as zero when the value is zero? Questions related to EJS lookang 3 4902 April 15, 2010, 08:10:10 pm by ahmedelshfie
Page created in 0.06 seconds with 23 queries.since 2011/06/15