[R] Plotting one dot in a graph

TGS cran.questions at gmail.com
Thu Aug 12 22:04:16 CEST 2010


I was meaning something like the following:

x <- seq(.2, .3, by = .01)
f <- function(x){
	x*cos(x)-2*x**2+3*x-1
}
plot(x,f(x), type = "l")
abline(h = -.1)

But I'm guessing "uniroot" will do this?---I haven't looked far into the uniroot function to see if it will solve this.

On Aug 12, 2010, at 1:00 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:54 PM, TGS wrote:

> Actually I spoke too soon David.
> 
> I'm looking for a function that will either tell me which point is the intersection so that I'd be able to plot a point there.
> 
> Or, if I have to solve for the roots in the ways which were demonstrated yesterday, then would I be able to specify what the horizontal line is, for instance in the case where y (is-not) 0?

Isn't the abline h=0 represented mathematically by the equation y=0 and therefore you are solving just for the zeros of "f" (whaich are the same as for (f-0)? If it were something more interesting, like solving the intersection of two polynomials, you would be solving for the  zeros of the difference of the equations. Or maybe I have not understood what you were requesting?


> 
> On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:
> 
> 
> On Aug 12, 2010, at 3:43 PM, TGS wrote:
> 
>> I'd like to plot a point at the intersection of these two curves. Thanks
>> 
>> x <- seq(.2, .3, by = .01)
>> f <- function(x){
>> 	x*cos(x)-2*x**2+3*x-1
>> }
>> 
>> plot(x,f(x), type = "l")
>> abline(h = 0)
> 
> Would this just be the uniroot strategy applied to "f"? You then plot the x and y values with points()
> 

> 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list