跳转到内容

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


这是一张修改过的图片,这意味着它已在原版本的基础上通过软件进行了编辑,改动内容:​converted into svg。其原始版本为:​RK Verfahren.png。修改者:​Tobi

 本W3C状态不明的统计图使用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:zh:知识共享
署名 相同方式共享
您可以自由地:
  • 共享 – 复制、发行并传播本作品
  • 修改 – 改编作品
惟须遵守下列条件:
  • 署名 – 您必须对作品进行署名,提供授权条款的链接,并说明是否对原始内容进行了更改。您可以用任何合理的方式来署名,但不得以任何方式表明许可人认可您或您的使用。
  • 相同方式共享 – 如果您再混合、转换或者基于本作品进行创作,您必须以与原先许可协议相同或相兼容的许可协议分发您贡献的作品。

说明

添加一行文字以描述该文件所表现的内容

此文件中描述的项目

描繪內容

image/svg+xml

文件历史

点击某个日期/时间查看对应时刻的文件。

日期/时间缩⁠略⁠图大小用户备注
当前2014年5月11日 (日) 13:372014年5月11日 (日) 13:37版本的缩略图720 × 450​(54 KB)T.gausterfixed typo, adjusted width and height
2014年5月11日 (日) 09:492014年5月11日 (日) 09:49版本的缩略图720 × 540​(54 KB)T.gausterUser created page with UploadWizard

以下页面使用本文件:

全域文件用途

以下其他wiki使用此文件:

元数据