# Intercept between two lines

4 messages
Open this post in threaded view
|
Report Content as Inappropriate

## Intercept between two lines

 Dear List, I know this is not the first post on this topic, but I need basic help I guess. Assuming the simple case of two lines with one intercept, how can I make R calculate this intercept, NOT using locator(). par (xaxs="i", yaxs="i") plot( 1, bty="n" ,xlim=c(0,300) , ylim=c(0,300) , xlab="X", ylab="Y")     curve(100-0.5*x, -50,250, add=T, col="blue")     curve(150- x   , -50,250, add=T, col="red") I want R to come up with the coordinates X=100, Y=50. Thank you for your help!
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Intercept between two lines

 Hi pannigh, The following might get you started: > x0 <- uniroot(function(x) 100-0.5*x - (150- x), c(0, 150))\$root > x0 [1] 100 > 100- 0.5*x0 [1] 50 HTH, Jorge.- On Wed, Apr 25, 2012 at 1:01 PM, pannigh <> wrote: > Dear List, > I know this is not the first post on this topic, but I need basic help I > guess. Assuming the simple case of two lines with one intercept, how can I > make R calculate this intercept, NOT using locator(). > > par (xaxs="i", yaxs="i") > plot( 1, bty="n" ,xlim=c(0,300) , ylim=c(0,300) , xlab="X", ylab="Y") >    curve(100-0.5*x, -50,250, add=T, col="blue") >    curve(150- x   , -50,250, add=T, col="red") > > I want R to come up with the coordinates X=100, Y=50. > > Thank you for your help! > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Intercept-between-two-lines-tp4587343p4587343.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] 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. >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: Intercept between two lines

 Thank you Jorge, this did get me started and who else might be interested in the topic, a possible code could be something like: #  Define the functions f1 <- function(x) 100-0.5*x                   f2 <- function(x) 150- x                     # Plot the functions par (xaxs="i", yaxs="i") plot( 1, bty="n" ,xlim=c(0,300) , ylim=c(0,300) , xlab="X", ylab="Y")     curve(100-0.5*x, -50,250, add=T, col="blue")     curve(150- x   , -50,250, add=T, col="red") # Calculate the intercept x0 <- uniroot(function(x) 100-0.5*x - (150- x), c(0, 250))\$root y0 <- f2(x0)   # f1(x0) gives the same result # Add the result to the plot points(x0,y0, pch=19, col=3, cex=2) text(x0+10,y0, adj=0, paste("S(",round(x0,2),",",round(y0,2),")", sep=""))