【问题标题】:My code only plot the last iteration. Logisticmap plotting in R我的代码只绘制最后一次迭代。 R中的Logisticmap绘图
【发布时间】:2020-12-29 07:13:25
【问题描述】:

我正在绘制逻辑图方程。我做了一个 for 循环来获取值,我想绘制所有这些值,但它只绘制最后一次迭代。我是 R 新手,是我的第一门编程语言。谢谢你的帮助。 :) 这是我的代码

n <- readline(prompt="Introduce el numero de iteraciones: ")
r <- readline(prompt="Introduce el parametro R: ")
xo <- readline(prompt="Introduce la condicion inicial x_o: ")



n <- as.numeric(n)
r <- as.numeric(r)
xo <- as.numeric(xo)



result <- 1:n
result[1] <- xo



for(i in 1:n){
  result[i+1] = r*result[i]*(1-result[i])
  print(result[[i+1]])
  plot(i, result[i+1])
}

【问题讨论】:

    标签: r plot


    【解决方案1】:

    一个选项是根据n 的值更改par 设置,然后在单个页面上更改plot

    par(mfrow = c(3, 3))
    for(i in 1:n){
       result[i+1] = r*result[i]*(1-result[i])
       print(result[[i+1]])
       plot(i, result[i+1])
     }
    

    或将所有绘图保存在单个pdf

    pdf("testing.pdf")
    for(i in 1:n){
      result[i+1] = r*result[i]*(1-result[i])
      print(result[[i+1]])
      plot(i, result[i+1])
     }
    
    dev.off()
    

    【讨论】:

      猜你喜欢
      • 2021-12-21
      • 1970-01-01
      • 2019-02-02
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      相关资源
      最近更新 更多