[R] Intercept between two lines

pannigh pannigh at gwdg.de
Thu Apr 26 11:23:28 CEST 2012


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=""))

--
View this message in context: http://r.789695.n4.nabble.com/Intercept-between-two-lines-tp4587343p4589304.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list