File:Runge-kutta.svg
From Wikimedia Commons, the free media repository
Jump to navigation
Jump to search
Size of this PNG preview of this SVG file: 720 × 450 pixels. Other resolutions: 320 × 200 pixels | 640 × 400 pixels | 1,024 × 640 pixels | 1,280 × 800 pixels | 2,560 × 1,600 pixels.
Original file (SVG file, nominally 720 × 450 pixels, file size: 54 KB)
File information
Structured data
Captions
Summary
[edit]DescriptionRunge-kutta.svg |
Deutsch: Runge-Kutta Methoden für die Differentialgleichung y'=sin(t)^2*y |
Date | |
Source |
|
Author |
This is a retouched picture, which means that it has been digitally altered from its original version. Modifications: converted into svg. The original can be viewed here: RK Verfahren.png: . Modifications made by Tobi.
|
R Code
[edit]# differential equation y'=sin(t)^2 * y
dy <- function(t, y) sin(t)^2 * y
# exact solution
exact <- function(t) 2 * exp(0.5*(t - sin(t)*cos(t)))
# euler's method
euler <- function(t, y, h, fun) {
y1 <- y + h*fun(t, y)
return(c(t + h, y1))
}
# heun's method
heun <- function(t, y, h, fun) {
yp <- y + h*fun(t, y)
y1 <- y + 0.5*h * (fun(t, y) + fun(t+h, yp))
return(c(t + h, y1))
}
# classical Runge–Kutta method
runge <- function(t, y, h, fun) {
y0 <- fun(t, y)
ya <- fun(t+h/2, y + h/2*y0)
yb <- fun(t+h/2, y + h/2*ya)
yc <- fun(t+h, y + h*yb)
y1 <- y + h/6*(y0 + 2*(ya+yb) + yc)
return(c(t + h, y1))
}
# step size = 0.5, last value = 5
h <- 0.5
niter <- 5/h
run <- eul2 <- eul <- heu <- data.frame(t=0, y=exact(0))
for(i in seq_len(niter)+1) {
eul[i, ] <- euler(t=eul$t[i-1], y=eul$y[i-1], h=h, fun=dy)
heu[i, ] <- heun (t=heu$t[i-1], y=heu$y[i-1], h=h, fun=dy)
run[i, ] <- runge(t=run$t[i-1], y=run$y[i-1], h=h, fun=dy)
}
# euler's method with reduced step size
h <- 0.25
niter <- 5/h
for(i in seq_len(niter)+1) {
eul2[i, ] <- euler(t=eul2$t[i-1], y=eul2$y[i-1], h=h, fun=dy)
}
# evaluating exact solution at
t <- seq(0, 5, 0.1)
# concatenating the methods into a data.frame
odesolve <- rbind(data.frame(t=t, y=exact(t), method="Exact Solution"),
data.frame(run, method="Runge-Kutta method"),
data.frame(heu, method="Heun's method"),
data.frame(eul2, method="Euler's method (reduced step size)"),
data.frame(eul, method="Euler's method"))
# translating into german
odesolve$method <- factor(odesolve$method,
levels=c("Exact Solution", "Runge-Kutta method",
"Heun's method",
"Euler's method (reduced step size)",
"Euler's method"),
labels=c("Exakte Lösung", "Klassisches Runge-Kutta",
"Heun", "Euler (halbe Schrittweite)",
"Euler"))
library(ggplot2)
p <- ggplot(odesolve, aes(x=t, y=y, col=method)) + geom_line() +
geom_point(data=subset(odesolve, as.numeric(method)!=1)) +
scale_color_discrete("") +
theme_bw() + theme(legend.position=c(0.02, 1), legend.justification=c(0, 1))
ggsave("runge-kutta.svg", width=8, height=6, plot=p)
Licensing
[edit]I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 13:37, 11 May 2014 | 720 × 450 (54 KB) | T.gauster (talk | contribs) | fixed typo, adjusted width and height | |
09:49, 11 May 2014 | 720 × 540 (54 KB) | T.gauster (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
The following page uses this file:
File usage on other wikis
The following other wikis use this file:
- Usage on de.wikipedia.org
- Usage on de.wikibooks.org
- Usage on en.wikipedia.org
- Usage on ko.wikipedia.org
- Usage on pl.wikipedia.org
- Usage on zh-yue.wikipedia.org
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Width | 576pt |
---|---|
Height | 360pt |