Message-ID: <6D68F27A-A1F4-4C5A-8272-536CC5D7EC75@comcast.net>
Date: 2011-01-03T15:26:23Z
From: David Winsemius
Subject: optimize
In-Reply-To: <alpine.LFD.2.00.1101031427300.7059@localhost6.localdomain6>
On Jan 3, 2011, at 9:52 AM, Muhammad Rahiz wrote:
> Hi all,
>
> I'm trying to get the value of y when x=203 by using the intersect
> of three curves. The horizontal curve does not meet with the other
> two. How can I rectify the code below?
Extend the appropriate axes. xlim and ylim are the arguments to use.
Looks too much like a homework problem for me to do the work for you,
though.
>
> Thanks
>
> Muhammad
>
> ts <- 1:10
> dd <- 10:1
>
> ts <- seq(200,209,1)
> dd <- c(NA,NA,NA,NA,1.87,1.83,1.86,NA,1.95,1.96)
>
> plot(ts,dd,ylim=c(1.5,2))
> abline(lm(dd~ts),col="blue",lty=2)
> abline(v=203,col="blue",lty=2)
>
> xy <- lm(dd~ts)
> fc <- function(x) coef(xy)[1] + x*coef(xy)[2]
> val <- optimize(f=function(x) abs(fc(x)-203),c(1.5,2))
> abline(h=val,col="blue",lty=2)
>
David Winsemius, MD
West Hartford, CT