Bill Simpson <wsi at gcal.ac.uk> writes:> I want to make a picture of a cos wave grating (pattern of fuzzy stripes). > First I try to make a plot of a cos wave: > x<-seq(1:100) > y<- 10*cos(2*pi*x*3/length(x)+0)+300 > plot(x,y) > That works fine. 3 cycles of cos wave. Now try for grating. > > time<-seq(1:100) > f<-function(x,time) 10*cos(2*pi*x*3/length(x)+0)+300 > z<-outer(x,time,f) > image(x,time,z) > I get a vertical grating as expected, BUT now I get <1 cycle of cos > wave. Varying the frequency (3 above) does nothing. I don't understand > what I am doing wrong.length(x) == 100 in the 1st case, == 1 in the 2nd. BTW: seq(1:100) is a bad idea. Try seq(99:100) to see why. Or seq(10:10). -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I want to make a picture of a cos wave grating (pattern of fuzzy stripes). First I try to make a plot of a cos wave: x<-seq(1:100) y<- 10*cos(2*pi*x*3/length(x)+0)+300 plot(x,y) That works fine. 3 cycles of cos wave. Now try for grating. time<-seq(1:100) f<-function(x,time) 10*cos(2*pi*x*3/length(x)+0)+300 z<-outer(x,time,f) image(x,time,z) I get a vertical grating as expected, BUT now I get <1 cycle of cos wave. Varying the frequency (3 above) does nothing. I don't understand what I am doing wrong. Thanks very much for any help. Bill -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 5 Oct 1999, Bill Simpson wrote:> I want to make a picture of a cos wave grating (pattern of fuzzy stripes). > First I try to make a plot of a cos wave: > x<-seq(1:100) > y<- 10*cos(2*pi*x*3/length(x)+0)+300 > plot(x,y) > That works fine. 3 cycles of cos wave. Now try for grating. > > time<-seq(1:100) > f<-function(x,time) 10*cos(2*pi*x*3/length(x)+0)+300 > z<-outer(x,time,f) > image(x,time,z) > I get a vertical grating as expected, BUT now I get <1 cycle of cos > wave. Varying the frequency (3 above) does nothing. I don't understand > what I am doing wrong.Which x were you expecting the length of? f is called inside outer, so try replacing length(x) by 100, as the x passed to f has length 100*100. Or (dangerous) f <- function(xx,time) 10*cos(2*pi*xx*3/length(x)+0)+300 -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, stats.ox.ac.uk/~ripley University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ben Bolker bolker at zoo.ufl.edu Zoology Department, University of Florida zoo.ufl.edu/bolker On Tue, 5 Oct 1999, Bill Simpson wrote:> Thanks very much for any help.Somebody'll probably answer this before I do -- but --> time<-seq(1:100) > f<-function(x,time) 10*cos(2*pi*x*3/length(x)+0)+300 > z<-outer(x,time,f) > image(x,time,z) > I get a vertical grating as expected, BUT now I get <1 cycle of cos > wave. Varying the frequency (3 above) does nothing. I don't understand > what I am doing wrong.> f<-function(x,time) 10*cos(2*pi*x*3/length(x)+0)+300^^^^^^^^^ here's the problem The "x" that's getting passed to "outer" is not what you expect. If you replace "length(x)" with 100 here, everything seems to do what you'd want.> > Bill > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ > >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._