File:Runge-kutta.svg
From Justapedia, unleashing the power of collective wisdom
Jump to navigation
Jump to search
![File:Runge-kutta.svg](https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Runge-kutta.svg/720px-Runge-kutta.svg.png)
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)
![]() | This is a file from the Wikimedia Commons. Information from its description page there is shown below. Commons is a freely licensed media file repository. You can help. |
Summary
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: ![]()
|
R Code
# 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
I, the copyright holder of this work, hereby publish it under the following license:
![w:en:Creative Commons](https://upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/90px-CC_some_rights_reserved.svg.png)
![attribution](https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/24px-Cc-by_new_white.svg.png)
![share alike](https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/24px-Cc-sa_white.svg.png)
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.
Captions
Add a one-line explanation of what this file represents
Items portrayed in this file
depicts
11 May 2014
image/svg+xml
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 17:37, 11 May 2014 | ![]() | 720 × 450 (54 KB) | wikimediacommons>T.gauster | fixed typo, adjusted width and height |
File usage
No pages on the Justapedia use this file (pages on other projects are not listed).
Metadata
This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
If the file has been modified from its original state, some details may not fully reflect the modified file.
Width | 576pt |
---|---|
Height | 360pt |
Retrieved from "https://justapedia.org/wiki/File:Runge-kutta.svg"