Skip to content
Back to formatted view

Raw Message

Message-ID: <2D06AE14D552497F9FB2A7928B92B11A@TuboPC>
Date: 2010-12-07T11:57:42Z
From: Tobias Schultze
Subject: Plotting own function

Hello,
I have a simple question but didn't find a solution.
How do I plot a custom function.

I have defined this function

func <- function(x) {
	y <- exp(-0.5*((x-63.9)/23.2)^2)
	if(x > 63.9)
		return(2 - y)
	else {
		return(y)
	}
}

and want to plot it in a specified range like

x = seq(-10,150,length=500)
y <- func(x)
plot(x,y,type="l",lwd=2,col="red")

But it doesn't work because it expects a vector but I need to compare the
scalar x.
How do I do it correctly?

Thanks a lot
Tobias