NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
August 17, 2019, 06:35:03 pm

Life well spent is long. ..."da Vinci (1452-1519, Italian artist, sculptor, painter, architect, engineer and scientist) "

 Pages: [1]   Go Down
 Author Topic: how to make a differentiation of a string?  (Read 8758 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member

Offline

Posts: 1792

http://weelookang.blogspot.com

 « Embed this message on: January 29, 2009, 04:24:36 pm » posted from:Singapore,,Singapore

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
 sfstring.PNG (47.59 KB, 1024x768 - viewed 482 times.) *** There are 1 more attached files. You need to login to acces it! « Last Edit: January 29, 2009, 09:23:42 pm by lookang » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3082

 « Embed this message Reply #1 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!
 Logged
lookang
Hero Member

Offline

Posts: 1792

http://weelookang.blogspot.com

 « Embed this message Reply #2 on: January 29, 2009, 09:23:05 pm » posted from:Singapore,,Singapore

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.

 « Last Edit: January 29, 2009, 09:58:43 pm by lookang » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3082

 « Embed this message Reply #3 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.
 Logged
lookang
Hero Member

Offline

Posts: 1792

http://weelookang.blogspot.com

 « Embed this message Reply #4 on: January 29, 2009, 09:54:58 pm » posted from:Singapore,,Singapore

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
 *** There are 1 more attached files. You need to login to acces it! « Last Edit: January 29, 2009, 09:59:33 pm by lookang » Logged
lookang
Hero Member

Offline

Posts: 1792

http://weelookang.blogspot.com

 « Embed this message Reply #5 on: January 30, 2009, 02:29:12 am » posted from:Singapore,,Singapore

it works now, need to refine it. thanks!
 *** There are 1 more attached files. You need to login to acces it! Logged
 Pages: [1]   Go Up
Life well spent is long. ..."da Vinci (1452-1519, Italian artist, sculptor, painter, architect, engineer and scientist) "