#----------------------------# # # # Loesungen UeBlatt13 # # # #----------------------------# # Aufgabe 1: ramp = colorRamp( c("white","black") ) ramp ramp( seq(0,1,length = 100) ) rgb( ramp(seq(0,1,length = 100)) , max=255 ) mycol = rgb( ramp(seq(0,1,length = 100)) , max=255 ) mycol # check: n = 100 sigma = seq(from = 1/2, to = 2, length=n) x = seq(from = -10, to=10, by=0.01) plot(x , dnorm(x,mean=0,sd=sigma[1]) ) for(i in 2:n) { points(x, dnorm(x,mean=0,sd=sigma[i]), col = mycol[i] ) } # Image-Plot Random-Potential: M = 100 N = 200 lattice = t(outer(1:N,1i*(1:M),FUN="+")) donors = sample(lattice,N*M/100,replace=FALSE) RandPot = matrix(0,nrow=M,ncol=N) for(donor in donors) { distances = sqrt(abs(lattice-donor)^2 + 15) RandPot = RandPot + 1/distances^3 } par(pin=c(6,6*M/N)) image(1:N, 1:M, t(RandPot), main="Random Potential", col=mycol ,xlab="" ) image(1:N, 1:M, t(RandPot), main="Random Potential", col=rev(mycol) ,xlab="" ) # Aufgabe 2 # eine Farbpalette von weiss nach gelb: ramp1 = colorRamp(c("white","yellow")) ramp1 mycol1 = rgb( ramp1(seq(0,1,length = 100) ), max = 255) mycol1 # quick check: n = 100 sigma = seq(from = 1/2, to = 2, length=n) plot(x , dnorm(x,mean=0,sd=sigma[1]) ) for(i in 2:n) { points(x, dnorm(x,mean=0,sd=sigma[i]), col = mycol1[i] ) } # soweit ok # eine Farbpalette von blau nach schwarz: ramp2 = colorRamp(c("blue","black")) ramp2 mycol2 = rgb( ramp2(seq(0,1,length = 100) ), max = 255) mycol2 # quick check: n = 100 plot(x , dnorm(x,mean=0,sd=sigma[1]) ) for(i in 2:n) { points(x, dnorm(x,mean=0,sd=sigma[i]), col = mycol2[i] ) } # soweit ok # rainbow()-Palette, eingeschraenkt auf das Intervall [gelb,blau]: # mit etwas probieren findet man die Grenzen fuer start und end: mycol0 = rainbow(500, start=1/6, end=4/6 ) mycol0 # quick check: n = 500 sigma = seq(from = 1/2, to = 2, length=n) plot(x , dnorm(x,mean=0,sd=sigma[1]) ) for(i in 2:n) { points(x, dnorm(x,mean=0,sd=sigma[i]), col = mycol0[i] ) } # soweit ok # Jetzt packen wir alles zusammen: mycol = c( mycol1 , mycol0 , mycol2 ) # check: n = 700 sigma = seq(from = 1/2, to = 2, length=n) plot(x , dnorm(x,mean=0,sd=sigma[1]) ) for(i in 2:n) { points(x, dnorm(x,mean=0,sd=sigma[i]), col = mycol[i] ) } # das passt # Image-Plot Random-Potential: M = 100 N = 200 lattice = t(outer(1:N,1i*(1:M),FUN="+")) donors = sample(lattice,N*M/100,replace=FALSE) RandPot = matrix(0,nrow=M,ncol=N) for(donor in donors) { distances = sqrt(abs(lattice-donor)^2 + 15) RandPot = RandPot + 1/distances^3 } par(pin=c(6,6*M/N)) image(1:N, 1:M, t(RandPot), main="Random Potential", col=mycol ,xlab="" ) image(1:N, 1:M, t(RandPot), main="Random Potential", col=rev(mycol) ,xlab="" )