Advertisement
Guest User

ZAJĘCIA 10

a guest
Jan 14th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.26 KB | None | 0 0
  1. ####10
  2. ##### Wykresy
  3. szereg_1 <- c(1,3,8,4,7)
  4. szereg_2 <- c(2,5,12,8,9)
  5.  
  6. plot( szereg_1, type = "l", col = "blue" )
  7. title( main = "Wykres_1", col.main = "red")
  8.  
  9. dev.off()
  10.  
  11. par( mar = c( 2, 2, 1, 0), mfrow = c ( 2, 2 ) )
  12.  
  13. zakres <- range(0, szereg_1, szereg_2 )
  14. plot ( szereg_1, type = "l", main = "Wykres", ylim = zakres )
  15. lines(szereg_2, col = "red", lty = 2, lwd = 3)
  16.  
  17.  
  18. set.seed(123)
  19. r_norm <- rnorm(1000)
  20.  
  21. hist(r_norm, freq = F, col = "blue", main = "Rozklad normalny", ylab = "Gestosc", xlab = "Kwantyle")
  22.  
  23. lines( density(r_norm), col = "red", lwd = 3 )
  24.  
  25. ###Bisekcja
  26. funkcja <- function(x) {
  27.   x  ^ 3 - 2 * x - 5
  28. }
  29. x_zakres <- seq (-3, 3, by = 0.01)
  30. y_zakres <- funkcja ( x_zakres )
  31. plot ( x = x_zakres, y = y_zakres, type = "l", col = "blue", lwd = 2, lty = 2)
  32. abline(h = 0)
  33. abline(v = 0)
  34.  
  35. bisekcja <- function( f, a, b, eps = 1e-16, maxiter = 100 ){
  36.   stopifnot( f( a ) * f (b) < 0 ) #Twierdzenie Darboux
  37.   for ( i in 1:maxiter ) {
  38.     c <- ( a +b ) / 2
  39.     if( abs(f( c ) ) < eps ) break
  40.     if( f( c ) * f( a ) > 0 ) { a <- c }else{ b <- c }
  41.   }
  42.   if ( i == maxiter ) { warning("Osiagnieto max iteracji") }  
  43.   list( root = c, f_root = f( c ) )
  44. }
  45.  
  46. m_zerowe_nasze <- bisekcja( funkcja, -3, 3)
  47. m_zerowe_R <- uniroot(funkcja, c(-3, 3) )
  48.  
  49. points ( x = m_zerowe_nasze$root, y = m_zerowe_nasze$f_root, col = "green", lwd = 3)
  50.  
  51.  
  52. #####ZADANIA
  53. Zadanie_1;
  54. a) Stworz wektor liczb od 1 do 1000 dodajac do niego wartosci losowe z rozkladu normalnego o sredniej 100 oraz o odchyleniu standardowym 10.
  55. b) Podziel powyzszy szerego na 6 rownych odcinkow.
  56. c) Stworz za pomoca petli for 6 wykresow liniowy stworzonych w jednym okienku podzielonym na 6 obszarow.
  57. d) Kazdy wykres stworzony jest na podstawie odcinkow z pkt b).
  58. e) Tytul wykresu powinien zmieniac sie dynamicznie od "Wykres_1" do "Wykres_6".
  59. f) Nazwa osi pionowej to "temperatura".
  60.  
  61.  
  62. #Zadanie_1:
  63. #a)
  64. a <- c(1:1000)
  65. b <- rnorm(1000,mean = 100, sd = 10)
  66. x <- a + b
  67. #b)
  68. y <- as.list(split(x, as.numeric(gl(length(x),167,length(x)))))
  69. #c)
  70. par(mar = c(2,4,2,1), mfrow = c(2,3))
  71.  
  72. wykresy <- function(list){
  73.   for (i in 1:6) {
  74.     plot(list[[i]], type = "l", main= paste("wykres_", i, sep = ""), ylab = "temperatura") #nwm czemu, ale wklejając tutaj zjadło mi type = ...
  75.   }
  76. }
  77.  
  78. wykresy(y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement