NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on January 29, 2009, 04:24:36 pm



Title: how to make a differentiation of a string?
Post by: lookang on January 29, 2009, 04:24:36 pm
I have an interface function field called fstring.

it read the string value in it and is pass to the graphics view as an analyticCurve with
X() = x
Y() = %fstring%

i am able to draw a nice graph say sin(x-t). perfect!


but how do i make a d(sin(x-t)/dt ?

i tried putting an evolution page

d(fstring)/dt = velocity

and make another analyticCurve

X() = x
Y() = velocity

doesn't seem to work, any idea how to make graph of d(fstring)/dt.

thanks!

if you want to see my xml, just delete the evolution page and it will run ;D


Title: Re: how to make a differentiation of a string?
Post by: Fu-Kwun Hwang on January 29, 2009, 06:09:28 pm
You can use AnalyticCurve to draw curve directly.
Since you used
Code:
double u = _view.waveFunction.evaluate(x,t);
to evaluate it's value in your code.

You can calculate u2=_view.waveFunction.evaluate(x,t-ddt);
And you can get du/dt with u2-u/ddt if ddt is small enough!
Just calculated it by definition!


Title: Re: how to make a differentiation of a string?
Post by: lookang on January 29, 2009, 09:23:05 pm
You can use AnalyticCurve to draw curve directly.
Since you used
Code:
double u = _view.waveFunction.evaluate(x,t);
to evaluate it's value in your code.

You can calculate u2=_view.waveFunction.evaluate(x,t-ddt);
And you can get du/dt with (u2-u)/ddt if ddt is small enough!
Just calculated it by definition!


it was a brilliant idea/method but it didn't solve the problem :( It is because the code above is for the n = 50 points that is spread out in the x-axis, the little points.


original code from paco and wolfgang seems to use the %string% method to draw the nice function.
guess it is difficult to get du/dx =  k*cos ( k*x - w*t) from a string u = sin ( k*x - w*t).

i go try your idea but on a separate loop.



Title: Re: how to make a differentiation of a string?
Post by: Fu-Kwun Hwang on January 29, 2009, 09:29:18 pm
You are differential it in time, so it should not matter if your points are spread out in space.
I do not understand why you said it is not working. May be you have another problem.

And becareful: It is not correct to write something like sin(x-t)
x and t is not the same dimension. You can not substract time from space

You can write sin(k*x-w*t). But sin(x-t) is meanless.


Title: Re: how to make a differentiation of a string?
Post by: lookang on January 29, 2009, 09:54:58 pm
You are differential it in time, so it should not matter if your points are spread out in space.
I do not understand why you said it is not working. May be you have another problem.

And becareful: It is not correct to write something like sin(x-t)
x and t is not the same dimension. You can not substract time from space

You can write sin(k*x-w*t). But sin(x-t) is meanless.


LOL agreed, sin(k*x-w*t), i was assuming k =1 and w =1 for quick typing :)

i now get strange simulation, think i debug tomorrow

found one bug!!
dudt = (u2-u)/ddt; // () is so important :)

let me give it some time to crack it before i ask u again :)

think i need
du/dx =  k*cos ( k*x - w*t) from a string u = sin ( k*x - w*t) instead of du/dt


Title: Re: how to make a differentiation of a string?
Post by: lookang on January 30, 2009, 02:29:12 am
it works now, need to refine it. thanks!