Adept Scientific - English
The world's best software and hardware for research, science and engineering.
flag arrow
clearclear

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKdedksvnofi
Home
Products
Training
Events
 Buy Online
Downloads
Academic Discounts
Support
My Adept
International |  About Us |  Adept Scientific Blog |  Contact Us |  Press Room |  Jobs
Adept Scientific on Facebook Adept Scientific on Twitter Adept Scientific on YouBube Adept Scientific on LinkedIn


The Next Steps

• Ask us a question
• Watch Maple Video Demonstrations
• Buy Maple Now
• View Maple Pricing
• Download a Brochure
• Request an Evaluation
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 17 Overview
Maple 17 Professional
Maple 17 Academic
Maple 17 Student Use
What's New in Maple 17
Maple Features
Maple History
Recorded Online Seminars

MapleSim
MapleNet
Maple T.A.
BlockImporter™
Maple Toolboxes
The Möbius Project

Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

Latest Information

New Features: Professional
New Features: Academic
Maple Features
The Maple Reporter Online

Service & Support

Maple Primes
blogs, forums etc

Elite Maintenance Program
Application Centre
Powertools
Search the Knowledge Base
Technical Support request

List Archives >  Maple User Group List Archive >  Archive by date >  This Month By Date >  This Month By Topic

[MUG] Re: Runge Kutta order 4

Search email archive for  

[MUG] Re: Runge Kutta order 4
Author: Maple Group    Posted: 01/11/2000 15:07:04 GMT
>> From: Maple Group

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Thu, 26 Oct 2000 14:40:24 -0700 (PDT)
From: Robert Israel
To:
Subject: Runge Kutta order 4



On Wed, 25 Oct 2000, Chuck Baker wrote:
> Is it possible to solve the following using Maple 6?

Yes, it is. But you shouldn't be asking this group to do your
homework for you.

Robert Israel
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2




-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Thu, 26 Oct 2000 15:45:56 -0700
To:
From: David Harrington
Subject: Runge Kutta order 4

This will do it all in Maple, but there is no difference between the real
and numerical solutions at the 4 digit accuracy with the rk4 method
(substitute foreuler for rk4 to see a difference, or use a bigger stepsize).
The formatting could be made nicer by using the printf command.

restart;de:={diff(y(x),x)=1-x+4*y(x),y(0)=1};

d
de := {-- y(x) = 1 - x + 4 y(x), y(0) = 1}
dx


> yanal:=rhs(dsolve(de,y(x)));

19
yanal := - 3/16 + 1/4 x + -- exp(4 x)
16

> ynum:=dsolve(de,y(x),numeric,method=classical[rk4],'stepsize'=0.01);

ynum := proc(x_classical) ... end proc

> ynum(1);

[x = 1, y(x) = 64.8977978130418052]

> for xx from 0 to 1 by 1/10 do
> evalf(xx,1),evalf(subs(x=xx,yanal),5),evalf(rhs(ynum(xx)[2]),5);
> od;


0., 1.0000, 1.
.1, 1.6090, 1.6090
.2, 2.5053, 2.5053
.3, 3.8301, 3.8301
.4, 5.7942, 5.7942
.5, 8.7121, 8.7120
.6, 13.052, 13.053
.7, 19.516, 19.516
.8, 29.146, 29.145
.9, 43.498, 43.498
1., 64.898, 64.898

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Thu, 26 Oct 2000 23:07:52 -0400 (EDT)
From: Carl DeVore
To:
Subject: Runge Kutta order 4



Yes, the whole thing is trivial in Maple and can be written in 10-15
minutes.

> restart;
> with(linalg):
> Digits:= trunc(evalhf(Digits)):
> IVP:= {diff(y(x), x) = 1-x+4*y(x), y(0)=1}:
> X:= array(1..101, [seq(.01*k, k= 0..100)]):
> Y[analytical]:= map(unapply(rhs(dsolve(IVP, {y(x)})), x), X):
> Y[RK4]:= col(dsolve
> (IVP
> ,{y(x)}
> ,type= numeric
> ,method= classical[rk4]
> ,value= X
> ,stepsize= .01
> )[2,1]
> ,2):
> stackmatrix
> (convert([`x-value`, `y-analytical`, `y-RK4`, `Abs. Error`], list)
> ,augment
> (X
> ,evalf(eval(Y[analytical]), 6)
> ,evalf(eval(Y[RK4]), 6)
> ,evalf(map(abs, evalm(Y[analytical]-Y[RK4])), 10)
> )
> );


... output deleted


Carl Devore
University of Delaware



-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Fri, 27 Oct 2000 07:56:13 -0400 (EDT)
From: John Little
Subject: Runge Kutta order 4
To:


Dear Chuck,

Don't mean to brag for Maple, but this kind of thing is
almost too easy -- a perfect illustration of the way Maple can
combine symbolic and numerical computation. You could also
plot the solution of your ODE in various ways.

Here's a Maple V procedure that generates the table of
exact solution values, Runge-Kutta approximations, and absolute
errors you asked for. I did this more or less ``off the top of my
head'', so some Maple purists might find better ways to do some of
the steps. I also didn't try to make the output pretty
and I didn't worry about trying to print out only the first
four decimal places in the numbers. About the numerical aspects:
Maple's default floating point number system uses 10 decimal digits
and the output was generated that way. There is also a
system variable called Digits you can set if you want to use
more or fewer decimal digits in floating point numbers.


RungeKuttaEx := proc()
#
# Generate approximate solution of y' = 1 - x + 4*y; y(0) = 1
# by the Classical RungeKutta Method and compare with analytic
# solution
#
#
local i, h, k1, k2, k3, k4 ,t, w, lastt, lastw, ansol, anval, f;

# first find the analytic solution of the IVP using dsolve

ansol := subs(dsolve({diff(y(x),x)=1+x-4*y(x),y(0)=1},y(x)),y(x));

# now set up for the Runge-Kutta method

f := (x,y) -> 1 + x - 4*y;
h := .01;
lastt := 0;
lastw := 1;
for i to 100 do
t := lastt + h;
k1 := f(lastt,lastw)*h;
k2 := f(lastt + h/2,lastw + k1/2)*h;
k3 := f(lastt + h/2,lastw + k2/2)*h;
k4 := f(t,lastw + k3)*h;
w := lastw + (k1 + 2*k2 + 2*k3 + k4)/6;
if evalb(i mod 10 = 0) then
anval:=evalf(subs(x=t,ansol));
lprint(`t=`,t,`exact value=`,anval,
`R-K approximation=`,w,`error=`,abs(w-anval));
fi;
lastw := w;
lastt := t:
od:
RETURN()
end:

The output:

> RungeKuttaEx();
t= .10 exact value= .7571350374 R-K approximation= .7571350422
error= .48e-8
t= .20 exact value= .6025797833 R-K approximation= .6025797899
error= .66e-8
t= .30 exact value= .5072202972 R-K approximation= .5072203037
error= .65e-8
t= .40 exact value= .4515409209 R-K approximation= .4515409265
error= .56e-8
t= .50 exact value= .4224599176 R-K approximation= .4224599226
error= .50e-8
t= .60 exact value= .4112083371 R-K approximation= .4112083411
error= .40e-8
t= .70 exact value= .4119081759 R-K approximation= .4119081790
error= .31e-8
t= .80 exact value= .4206192907 R-K approximation= .4206192930
error= .23e-8
t= .90 exact value= .4347005245 R-K approximation= .4347005261
error= .16e-8
t= 1.00 exact value= .4523814566 R-K approximation= .4523814579
error= .13e-8


John B. Little
Dept. of Mathematics and Computer Science
College of the Holy Cross
Worcester, MA 01610 USA
(508) 793-2274
email:
homepage: http://math.holycross.edu/~little/homepage.html



[View Complete Thread]



Previous by date: [MUG] Re: undefined limits, Maple Group
Next by date: [MUG] Re: programming a table, Maple Group
Previous thread: [MUG] textplot(3d) busted - workaround?, Luis Goddyn
Next thread: [MUG] programming a table, Herg2770



Ready to buy?

Maple Professional
Add to shopping basket
£ 1,695.00
Maple - for academic use
Add to shopping basket
£ 940.00
Maple - for registered students
Add to shopping basket
£ 95.00

Featured Downloads

Maplesoft Product Catalogue
Maple Player for iPad - Datasheet
Maple 17 What's New datasheet
Maple 17 Professional Datasheet
Maple Whitepaper: Driving Innovation - How mathematical modeling and optimisation increase efficiency and productivity in vehicle design.
MapleSim Whitepaper - Technological Superiority in Multi-Domain Physical Modelling and Simulation

Latest Downloads

Maple - Global Optimization Toolbox
The Möbius Project - Create it, Share it, Grade it
Maple 17 Programming Guide
Maple 17 User Manual
Maplesoft Product Catalogue - Academic Maths

Product Reviews

"Without the Maple software, we would have to spend weeks generating the equations of motion for every experiment. Then the chances that we did it right would basically be near zero. There would always be a mistake somewhere. It is very difficult to set up a dynamic motion model by hand."
- Jean-Claude PiedBeouf, Ph.D Manager of Robotics, Canadian Space Agency

"Its very good - highly accurate and easy to use. The speed of Maple allows me to change equations and quickly reintegrate them into the application, so more possibilities can be explored to achieve the precise effect desired."
Shawn Neely, Senior R & D Director for PDI/Dreamworks

Latest News

Global Optimization Toolbox: Better Optimization to Solve More Problems, Faster
Global Optimization Toolbox: Better Optimization to Solve More Problems, Faster
New MapleSim release delivers advanced model development and analysis, extended toolchain connectivity and quicker results
Maple 17 offers advanced solving and application development capabilities
New release of Maple advances teaching and research
adept

Top of the Page

Popular Links: ChemDraw | ChemOffice | Data Acquisition | Data Analysis | EndNote | Maple | MapleSim | Mathcad | MathType | Quality Analyst | Reference Manager | VisSim

EU ePrivacy Directive | Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2013, Adept Scientific Ltd.
Site designed and maintained by Lyndon Ash

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055