Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####10
- ##### Wykresy
- szereg_1 <- c(1,3,8,4,7)
- szereg_2 <- c(2,5,12,8,9)
- plot( szereg_1, type = "l", col = "blue" )
- title( main = "Wykres_1", col.main = "red")
- dev.off()
- par( mar = c( 2, 2, 1, 0), mfrow = c ( 2, 2 ) )
- zakres <- range(0, szereg_1, szereg_2 )
- plot ( szereg_1, type = "l", main = "Wykres", ylim = zakres )
- lines(szereg_2, col = "red", lty = 2, lwd = 3)
- set.seed(123)
- r_norm <- rnorm(1000)
- hist(r_norm, freq = F, col = "blue", main = "Rozklad normalny", ylab = "Gestosc", xlab = "Kwantyle")
- lines( density(r_norm), col = "red", lwd = 3 )
- ###Bisekcja
- funkcja <- function(x) {
- x ^ 3 - 2 * x - 5
- }
- x_zakres <- seq (-3, 3, by = 0.01)
- y_zakres <- funkcja ( x_zakres )
- plot ( x = x_zakres, y = y_zakres, type = "l", col = "blue", lwd = 2, lty = 2)
- abline(h = 0)
- abline(v = 0)
- bisekcja <- function( f, a, b, eps = 1e-16, maxiter = 100 ){
- stopifnot( f( a ) * f (b) < 0 ) #Twierdzenie Darboux
- for ( i in 1:maxiter ) {
- c <- ( a +b ) / 2
- if( abs(f( c ) ) < eps ) break
- if( f( c ) * f( a ) > 0 ) { a <- c }else{ b <- c }
- }
- if ( i == maxiter ) { warning("Osiagnieto max iteracji") }
- list( root = c, f_root = f( c ) )
- }
- m_zerowe_nasze <- bisekcja( funkcja, -3, 3)
- m_zerowe_R <- uniroot(funkcja, c(-3, 3) )
- points ( x = m_zerowe_nasze$root, y = m_zerowe_nasze$f_root, col = "green", lwd = 3)
- #####ZADANIA
- Zadanie_1;
- a) Stworz wektor liczb od 1 do 1000 dodajac do niego wartosci losowe z rozkladu normalnego o sredniej 100 oraz o odchyleniu standardowym 10.
- b) Podziel powyzszy szerego na 6 rownych odcinkow.
- c) Stworz za pomoca petli for 6 wykresow liniowy stworzonych w jednym okienku podzielonym na 6 obszarow.
- d) Kazdy wykres stworzony jest na podstawie odcinkow z pkt b).
- e) Tytul wykresu powinien zmieniac sie dynamicznie od "Wykres_1" do "Wykres_6".
- f) Nazwa osi pionowej to "temperatura".
- #Zadanie_1:
- #a)
- a <- c(1:1000)
- b <- rnorm(1000,mean = 100, sd = 10)
- x <- a + b
- #b)
- y <- as.list(split(x, as.numeric(gl(length(x),167,length(x)))))
- #c)
- par(mar = c(2,4,2,1), mfrow = c(2,3))
- wykresy <- function(list){
- for (i in 1:6) {
- plot(list[[i]], type = "l", main= paste("wykres_", i, sep = ""), ylab = "temperatura") #nwm czemu, ale wklejając tutaj zjadło mi type = ...
- }
- }
- wykresy(y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement