Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Mathematics / Numerical Analysis / October 2008



Tip: Looking for answers? Try searching our database.

Help on runge-kutta

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lasse.Karagiannis@swipnet.se - 03 Oct 2008 10:20 GMT
Hello, I am trying to grasp the runge-kutta method, and I am trying to
solve
Newtons equation of motion for a mass konncted to a spring and a
damper.
m*x´´= -k*x - b*x´+m*g
I am solving this in two steps
I have
m*dv/dt=-k*x - b*x´+m*g
v_i+1 = [-(k/m)*x_i -(b/m)*v_i +g]*dt  + v_i =f_v (x_i, v_i, t_i)*dt +
v_i

x_i+1 = v_i*dt + x_i   =  f_x(x_i,v_i,t_i)*dt +x_i
These are with Euler-forward

Then I take the Runge-kutta step as
v_i+1=v_i + (dt/6)*(vk0+2*vk1+2*vk2+vk3), and
x_i+1=x_i + (dt/6)*(xk0+2*xk1+2*xk2+xk3)

I've taken k-slopes as:
vk0=f_v(x_i, v_i, t_i)= -(k/m)*x_i -(b/m)*v_i +g
vk1=f_v( x_i + xk0*(dt/2), v_i + vk0*(dt/2), t_i+dt/2)= -(k/m)*{x_i
+xk0*(dt/2)} - (b/m)*{v_i+vk0*(dt/2)} +g
vk2=f_v( x_i + xk1*(dt/2), v_i + vk1*(dt/2), t_i+dt/2)= -(k/m)*{x_i
+xk1*(dt/2)} - (b/m)*{v_i+vk1*(dt/2)} +g
vk3=f_v( x_i + xk2*dt, v_i + vk2*dt, t_i+dt)= -(k/m)*{x_i +xk2*dt} -
(b/m)*{v_i+vk2*dt} +g

xk0=f_x(x_i, v_i, t_i)= v_i
xk1=f_x( x_i + xk0*(dt/2), v_i + vk0*(dt/2), t_i+dt/2)= v_i + vk0*(dt/
2)
xk2=f_x( x_i + xk1*(dt/2), v_i + vk1*(dt/2), t_i+dt/2)= v_i + vk1*(dt/
2)
xk3=f_x( x_i + xk2*dt, v_i + vk2*dt, t_i+dt)=v_i+vk2*dt

I get horribel results. I've implemented the above in Excel.

Could somebody help me.
greatful for any help

Kindest regards,
Lasse Karagiannis
Lasse.Karagiannis@swipnet.se - 03 Oct 2008 11:59 GMT
If somebody want's to see the equations in formatted text, I can send
a MS Word document.
Just mail me at Lasse.Karagiannis%%%%£££££££$$$$$777++++++++++++++++%
%hotmail.com
Alois Steindl - 03 Oct 2008 12:24 GMT
Hello,
just convert your equations to a first order system and apply
Runge-Kutta to that.
Using Excel must be a horror for that kind of problems.

Good luck
Alois

Signature

Alois Steindl,                           Tel.: +43 (1) 58801 / 32558      
Inst. for Mechanics and Mechatronics     Fax.: +43 (1) 58801 / 32598
Vienna University of Technology,         A-1040 Wiedner Hauptstr. 8-10

Bart - 03 Oct 2008 12:48 GMT
> Hello, I am trying to grasp the runge-kutta method, and I am trying to
> solve Newtons equation of motion for a mass konncted to a spring and a
[quoted text clipped - 3 lines]
>
> I get horribel results. I've implemented the above in Excel.

Lasse,

I haven't looked at your equations (yet), but as Alois mentions,
it is probably wiser and better to try to implement this in a
programming language that is more suited for numerical
computations.  My recommendation is to use Octave:
http://www.octave.org .  It works on both Windows and Linux, has
a not so steep learning curve and you should start to feel
comfortable with it within no time.

Kind regards,
Bart

--
JCH - 03 Oct 2008 17:58 GMT
Hello, I am trying to grasp the runge-kutta method, and I am trying to
solve
Newtons equation of motion for a mass konncted to a spring and a
damper.
m*x´´= -k*x - b*x´+m*g
I am solving this in two steps
I have
m*dv/dt=-k*x - b*x´+m*g
v_i+1 = [-(k/m)*x_i -(b/m)*v_i +g]*dt  + v_i =f_v (x_i, v_i, t_i)*dt +
v_i

x_i+1 = v_i*dt + x_i   =  f_x(x_i,v_i,t_i)*dt +x_i
These are with Euler-forward

Then I take the Runge-kutta step as
v_i+1=v_i + (dt/6)*(vk0+2*vk1+2*vk2+vk3), and
x_i+1=x_i + (dt/6)*(xk0+2*xk1+2*xk2+xk3)

I've taken k-slopes as:
vk0=f_v(x_i, v_i, t_i)= -(k/m)*x_i -(b/m)*v_i +g
vk1=f_v( x_i + xk0*(dt/2), v_i + vk0*(dt/2), t_i+dt/2)= -(k/m)*{x_i
+xk0*(dt/2)} - (b/m)*{v_i+vk0*(dt/2)} +g
vk2=f_v( x_i + xk1*(dt/2), v_i + vk1*(dt/2), t_i+dt/2)= -(k/m)*{x_i
+xk1*(dt/2)} - (b/m)*{v_i+vk1*(dt/2)} +g
vk3=f_v( x_i + xk2*dt, v_i + vk2*dt, t_i+dt)= -(k/m)*{x_i +xk2*dt} -
(b/m)*{v_i+vk2*dt} +g

xk0=f_x(x_i, v_i, t_i)= v_i
xk1=f_x( x_i + xk0*(dt/2), v_i + vk0*(dt/2), t_i+dt/2)= v_i + vk0*(dt/
2)
xk2=f_x( x_i + xk1*(dt/2), v_i + vk1*(dt/2), t_i+dt/2)= v_i + vk1*(dt/
2)
xk3=f_x( x_i + xk2*dt, v_i + vk2*dt, t_i+dt)=v_i+vk2*dt

I get horribel results. I've implemented the above in Excel.

*** JCH

See Microsoft VBA algorithm for Excel

* http://home.arcor.de/janch/janch/_news/20081003-runge-kutta/

Signature

Regards/Grüße    http://home.arcor.de/janch/janch/menue.htm
Jan C. Hoffmann  eMail aktuell: janch@nospam.arcornews.de
                Microsoft-kompatibel/optimiert für IE7+OE7

Lasse.Karagiannis@swipnet.se - 03 Oct 2008 19:32 GMT
Thank you all.

Jan, I am a beginner on Excel. How do I run the code?

Kindest regards,

Lasse
Ken - 03 Oct 2008 21:26 GMT
Another alternative is to use an Excel Add-In call XNUMBERS:

http://digilander.libero.it/foxes/SoftwareDownload.htm

Look for "XNUMBERS 5.6 - Multi Precision Floating Point Computing and
Numerical Methods for EXCEL" near the top.

They have very clear documentation, including a specific example on
RK4:

http://digilander.libero.it/foxes/Documents.htm

Look for "Numeric calculus in Excel Xnumbers Tutorial vol.1,Oct. 2007
by Foxes Team. (PDF 2.8 MB Zip)" near the top.
JCH - 04 Oct 2008 06:11 GMT
> Another alternative is to use an Excel Add-In call XNUMBERS:
>
[quoted text clipped - 10 lines]
> Look for "Numeric calculus in Excel Xnumbers Tutorial vol.1,Oct. 2007
> by Foxes Team. (PDF 2.8 MB Zip)" near the top.

Yes, a good reference. But I couldn't find a 2nd order Runge Kutta ODE.

Signature

Regards/Grüße    http://home.arcor.de/janch/janch/menue.htm
Jan C. Hoffmann  eMail aktuell: janch@nospam.arcornews.de
                Microsoft-kompatibel/optimiert für IE7+OE7

foxes - 08 Oct 2008 18:27 GMT
> > Another alternative is to use an Excel Add-In call XNUMBERS:
>
[quoted text clipped - 19 lines]
>
> - Mostra testo citato -

Hi all,
It is a numeric calculus problem , not a tool problem.
You can solve your differenzial equation with the tool that you like
(Excel, Matlab, Scilab, Octave, ecc)

With Xnumbers you can solve easily your ODE with many algorithms:
(Runge-Kutta 4, Implicit A-stable algorithm, Runge-Kutte-Feldberg 4.5,
Exponential, Finite differences, etc.).
For using these feauture, please, consult the ODE_Tutoria pdf
at pag 38 it is showing how to solve just your 2nd order equation

http://digilander.libero.it/foxes/diffequ/ODE_tutorial.pdf

The problem is the integration step that depends on the parameter m,
k, b, g (that you have not mentioned)
I have try to solve the ODE using the function ODE_RK4 (Runge-Kutta 4
order) with this parameters: m = 2 kg (mass), k= 10 (elastic
constant), b = 3 (damping factor), g = 9,8 (acc. gravity) obtaining a
good result, with a step dt = 0.05 and 200 steps.
Of course I have also implentented you code in VBA Excel
I have only correct the assignement operator because you use two "="
for each line
and this is accepted in VB but has anothe meaning: it return TRUE or
FALSE, not the correct numerica value.

the correrect implementation is the following
(I don't know if it is allowed to attach file. If you want I can send
you the xls file with the macro at your private e-mail)
Hope this help you.
Good calculation.

Leonardo Volpi
Foxes Team, Italy
----------------------------
Code implementing Runge Kutta 4
<<<<...

Sub rk4_test()

'declaration
Dim imax, i, dt, t_i, x_i, v_i, v_i_1, x_i_1
Dim vk0, vk1, vk2, vk3, xk0, xk1, xk2, xk3

'parameter setting
k = 10
m = 1
b = 3
g = 9.8

dt = 0.05 'integration step
imax = 200 'max step
i = 0

'initial conditions
t_i = 0
x_i = 0
v_i = 0

'RK4 starts
Do
vk0 = f_v(x_i, v_i, t_i)
vk1 = f_v(x_i + xk0 * (dt / 2), v_i + vk0 * (dt / 2), t_i + dt / 2)
vk2 = f_v(x_i + xk1 * (dt / 2), v_i + vk1 * (dt / 2), t_i + dt / 2)
vk3 = f_v(x_i + xk2 * dt, v_i + vk2 * dt, t_i + dt)

xk0 = f_x(x_i, v_i, t_i)
xk1 = f_x(x_i + xk0 * (dt / 2), v_i + vk0 * (dt / 2), t_i + dt / 2)
xk2 = f_x(x_i + xk1 * (dt / 2), v_i + vk1 * (dt / 2), t_i + dt / 2)
xk3 = f_x(x_i + xk2 * dt, v_i + vk2 * dt, t_i + dt)

v_i_1 = v_i + (dt / 6) * (vk0 + 2 * vk1 + 2 * vk2 + vk3)
x_i_1 = x_i + (dt / 6) * (xk0 + 2 * xk1 + 2 * xk2 + xk3)

debug.print i, t_i, x_i, v_i

i = i + 1
v_i = v_i_1
x_i = x_i_1
t_i = t_i + dt

Loop Until i > imax

exit sub

Private Function f_v(x_i, v_i, t_i)
f_v = -(k / m) * x_i - (b / m) * v_i + g
End Function

Private Function f_x(x_i, v_i, t_i)
f_x = v_i
End Function

<<<<...
JCH - 10 Oct 2008 14:25 GMT
On 4 Ott, 07:11, "JCH" <ja...@nospam.arcornews.de> wrote:
> "Ken" <ken.al...@sbcglobal.net> schrieb im
> Newsbeitragnews:552e5154-39ea-4831-8bfc-0025b9a1870c@v28g2000hsv.googlegroups.com...
[quoted text clipped - 22 lines]
>
> - Mostra testo citato -

Hi all,
It is a numeric calculus problem , not a tool problem.
You can solve your differenzial equation with the tool that you like
(Excel, Matlab, Scilab, Octave, ecc)

With Xnumbers you can solve easily your ODE with many algorithms:
(Runge-Kutta 4, Implicit A-stable algorithm, Runge-Kutte-Feldberg 4.5,
Exponential, Finite differences, etc.).
For using these feauture, please, consult the ODE_Tutoria pdf
at pag 38 it is showing how to solve just your 2nd order equation

http://digilander.libero.it/foxes/diffequ/ODE_tutorial.pdf

The problem is the integration step that depends on the parameter m,
k, b, g (that you have not mentioned)
I have try to solve the ODE using the function ODE_RK4 (Runge-Kutta 4
order) with this parameters: m = 2 kg (mass), k= 10 (elastic
constant), b = 3 (damping factor), g = 9,8 (acc. gravity) obtaining a
good result, with a step dt = 0.05 and 200 steps.
Of course I have also implentented you code in VBA Excel
I have only correct the assignement operator because you use two "="
for each line
and this is accepted in VB but has anothe meaning: it return TRUE or
FALSE, not the correct numerica value.

the correrect implementation is the following
(I don't know if it is allowed to attach file. If you want I can send
you the xls file with the macro at your private e-mail)
Hope this help you.
Good calculation.

Leonardo Volpi
Foxes Team, Italy
----------------------------
Code implementing Runge Kutta 4
<<<<...

Sub rk4_test()

'declaration
Dim imax, i, dt, t_i, x_i, v_i, v_i_1, x_i_1
Dim vk0, vk1, vk2, vk3, xk0, xk1, xk2, xk3

'parameter setting
k = 10
m = 1
b = 3
g = 9.8

dt = 0.05 'integration step
imax = 200 'max step
i = 0

[...]

***JCH

Using parameters above: See Page 5

* http://home.arcor.de/janch/janch/_news/20081010-runge-kutta/

Signature

Regards/Grüße    http://home.arcor.de/janch/janch/menue.htm
Jan C. Hoffmann  eMail aktuell: janch@nospam.arcornews.de
                Microsoft-kompatibel/optimiert für IE7+OE7

pnachtwey - 10 Oct 2008 19:40 GMT
> Using parameters above: See Page 5
Page 5 looks good assuming g is positive rather than negative. The
formula on page 1 is wrong.  Replace the -Kx with -Ky and you will not
be confusing anybody that looks at your web pages.

The fact that no one mentioned the obvious error makes me wonder if
anyone is paying attention.

Peter Nachtwey
JCH - 10 Oct 2008 20:48 GMT
On Oct 10, 6:25 am, "JCH" <ja...@nospam.arcornews.de> wrote:
> Using parameters above: See Page 5
Page 5 looks good assuming g is positive rather than negative. The
formula on page 1 is wrong.  Replace the -Kx with -Ky and you will not
be confusing anybody that looks at your web pages.

The fact that no one mentioned the obvious error makes me wonder if
anyone is paying attention.

*** JCH

It's just a typo on the graph (Page 1). I corrected the graph. The
calculation was done correctly using -k*y (Page 2).

* http://home.arcor.de/janch/janch/_news/20081011-runge-kutta/

Signature

Regards/Grüße    http://home.arcor.de/janch/janch/menue.htm
Jan C. Hoffmann  eMail aktuell: janch@nospam.arcornews.de
                Microsoft-kompatibel/optimiert für IE7+OE7

JCH - 04 Oct 2008 06:13 GMT
> Thank you all.
>
> Jan, I am a beginner on Excel. How do I run the code?

- Activate Macros
- First have a sheet named "Table"
- Go via "Macros" to "Visual Basic Editor"
- Insert a module via context menue clicking "Input"
- Copy the code into module
- Get your cursor into code "RungeKuttaTest()"
- Run it (click triangle in menue)
- You get numbers (solution) in "Table"
- Make a Graph with these numbers (see manual, F1)

See for Excel 2007

* http://home.arcor.de/janch/janch/_news/20081004-runge-kutta/

Page 3 and 4

Signature

Regards/Grüße    http://home.arcor.de/janch/janch/menue.htm
Jan C. Hoffmann  eMail aktuell: janch@nospam.arcornews.de
                Microsoft-kompatibel/optimiert für IE7+OE7

Dieter Britz - 06 Oct 2008 09:00 GMT
> Hello, I am trying to grasp the runge-kutta method, and I am trying to
> solve
[quoted text clipped - 37 lines]
> Kindest regards,
> Lasse Karagiannis

Explicit RK is not unconditionally stable. This means that there is a
limit  on how large your dt can be. Try reducing it.
Signature

Dieter Britz (oldnob<at>yahoo.dk)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.