Le 14 Octobre 2004 16:24, Pedro Rodrigues de Almeida a écrit : > Hi there, > > How can I plot a function in R which is defined by conditional > branches?, e.g.: > > u(x) = 1, Ed<x<2Ed (where Ed is a positive constant, say, 25); > u(x)=0.5*x, x>2Ed > > curve(u(x), ....) > > So far I have had to use curve(..., add=TRUE) with two function define > by segments, i.e., two branches or intervals for the variable x, say, > 25,50 and then from 50,... and I would appreciate a more elegant > solution if possible. > > Thanks a lot, > > Pedro Rodrigues de Almeida > Helsinki - Finland
Have you tried something along the lines of: u <- function(x, Ed) ifelse(x > 2 * Ed, 0.5 * x, 1) curve(u(x), ...) (Note that this does take the case x <= Ed into account, which is not covered in your definition.) HTH -- Vincent Goulet, Associate Professor École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca ______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html