File:Runge-kutta.svg

頁面內容唔支援其他語言。
出自維基百科,自由嘅百科全書

原本檔案(SVG檔案,表面大細: 720 × 450 像素,檔案大細:54 KB)

摘要

描述
Deutsch: Runge-Kutta Methoden für die Differentialgleichung y'=sin(t)^2*y
English: Runge–Kutta, Heun and Euler methods for the differential equation y'=sin(t)^2*y
日期
來源
作者

Svchb


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.

 
This W3C-unspecified chart was created with R.

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)

協議

我,呢份作品嘅作者,決定用以下許可發佈呢件作品:
w:en:Creative Commons
署名 相同方式分享
你可以:
  • 去分享 – 複製、發佈同傳播呢個作品
  • 再改 – 創作演繹作品
要遵照下面嘅條件:
  • 署名 – 你一定要畀合適嘅表彰、畀返指向呢個授權條款嘅連結,同埋寫明有無改過嚟。你可以用任何合理方式去做,但唔可以用任何方式暗示授權人認可咗你或者你嘅使用方式。
  • 相同方式分享 – 如果你用任何方式改過呢個作品,你必須要用返原本或者相似嘅條款發佈。

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

圖中顯示嘅係

11 5 2014

image/svg+xml

檔案歷史

撳個日期/時間去睇響嗰個時間出現過嘅檔案。

日期/時間縮圖尺寸用戶註解
現時2014年5月11號 (日) 13:37響2014年5月11號 (日) 13:37嘅縮圖版本720 × 450(54 KB)T.gausterfixed typo, adjusted width and height
2014年5月11號 (日) 09:49響2014年5月11號 (日) 09:49嘅縮圖版本720 × 540(54 KB)T.gausterUser created page with UploadWizard

以下嘅1版用到呢個檔:

全域檔案使用情況

下面嘅維基都用緊呢個檔案:

Metadata