[R] custom function that plots other functions- problem

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sun May 5 19:55:52 CEST 2013


This request is clearly off-topic according to the Posting Guide. Please use the study assistance provided in the context of your assignment.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

"Bartłomiej Drążczyk" <bartek.drazczyk at gmail.com> wrote:

>Hi everyone!
>
>Could you please help me with the following assignment? My aim is to
>write
>a custom function that draws the plots of functions submitted by the
>user.
>The catch is, that we do not know the exact number of functions the
>user
>will select to draw.
>
>The program is relatively easy with one function, f.e sin:
>
>mf<- function(f,range,quality){
>
>                x<- seq(range[1],range[2], quality);
>
>                y<- f(x);
>
>                plot(x,y);
>}
>
>mp(sin, c(0,2*pi), .02);
>
>but I encountered some problems while trying to provide more than one-
>the
>following structure generates mistakes:
>
>plotter<- function(f,howmany,range,quality){
>    x<-seq(range[1],range[2],quality)
>    y<- matrix(f,how_many)
>    plot(x,y[1,])
>    for(i in 2:how_many){
>    lines(x,y[i,])
>    }
>}
>
>plotter<-(c(sin(x),cos(x)),2,c(0,2*pi),.02)
>
>I would really appreciate your help with this program.
>
>Regards,
>Bartek
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list