Well - the _procedure_ will give a result. But think of f(x) = {-1; x <= 1/3 and 1; x > 1/3 What should inf{x| F(x) >= 0} be? What should the procedure return?> On Apr 10, 2017, at 10:38 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: > > Given what she said, how does the procedure I suggested fail? > > (Always happy to be corrected). > > -- Bert > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Mon, Apr 10, 2017 at 1:57 AM, Boris Steipe <boris.steipe at utoronto.ca> wrote: >> Are you sure this is trivial? I have the impression the combination of an ill-posed problem and digital representation of numbers might just create the illusion that is so. >> >> B. >> >> >> >> >>> On Apr 10, 2017, at 12:34 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: >>> >>> Then it's trivial. Check values at the discontinuities and find the >>> first where it's <0 at the left discontinuity and >0 at the right, if >>> such exists. Then just use zero finding on that interval (or fit a >>> line if everything's linear). If none exists, then just find the first >>> discontinuity where it's > 0. >>> >>> Cheers, >>> Bert >>> >>> >>> Bert Gunter >>> >>> "The trouble with having an open mind is that people keep coming along >>> and sticking things into it." >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>> >>> >>> On Sun, Apr 9, 2017 at 5:38 PM, li li <hannah.hlx at gmail.com> wrote: >>>> Hi Burt, >>>> Yes, the function is monotone increasing and points of discontinuity are >>>> all known. >>>> They are all numbers between 0 and 1. Thanks very much! >>>> Hanna >>>> >>>> >>>> 2017-04-09 16:55 GMT-04:00 Bert Gunter <bgunter.4567 at gmail.com>: >>>>> >>>>> Details matter! >>>>> >>>>> 1. Are the points of discontinuity known? This is critical. >>>>> >>>>> 2. Can we assume monotonic increasing, as is shown? >>>>> >>>>> >>>>> -- Bert >>>>> >>>>> >>>>> >>>>> >>>>> Bert Gunter >>>>> >>>>> "The trouble with having an open mind is that people keep coming along >>>>> and sticking things into it." >>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>>>> >>>>> >>>>> On Sun, Apr 9, 2017 at 1:28 PM, li li <hannah.hlx at gmail.com> wrote: >>>>>> Dear all, >>>>>> For a piecewise function F similar to the attached graph, I would like >>>>>> to >>>>>> find >>>>>> inf{x| F(x) >=0}. >>>>>> >>>>>> >>>>>> I tried to uniroot. It does not seem to work. Any suggestions? >>>>>> Thank you very much!! >>>>>> Hanna >>>>>> >>>>>> ______________________________________________ >>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>>>> 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. >>>> >>>> >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> 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. >>
Yup, she can decide. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Apr 10, 2017 at 7:56 AM, Boris Steipe <boris.steipe at utoronto.ca> wrote:> Well - the _procedure_ will give a result. > > But think of f(x) = {-1; x <= 1/3 and 1; x > 1/3 > > What should inf{x| F(x) >= 0} be? > What should the procedure return? > > > > > >> On Apr 10, 2017, at 10:38 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: >> >> Given what she said, how does the procedure I suggested fail? >> >> (Always happy to be corrected). >> >> -- Bert >> Bert Gunter >> >> "The trouble with having an open mind is that people keep coming along >> and sticking things into it." >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >> >> >> On Mon, Apr 10, 2017 at 1:57 AM, Boris Steipe <boris.steipe at utoronto.ca> wrote: >>> Are you sure this is trivial? I have the impression the combination of an ill-posed problem and digital representation of numbers might just create the illusion that is so. >>> >>> B. >>> >>> >>> >>> >>>> On Apr 10, 2017, at 12:34 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: >>>> >>>> Then it's trivial. Check values at the discontinuities and find the >>>> first where it's <0 at the left discontinuity and >0 at the right, if >>>> such exists. Then just use zero finding on that interval (or fit a >>>> line if everything's linear). If none exists, then just find the first >>>> discontinuity where it's > 0. >>>> >>>> Cheers, >>>> Bert >>>> >>>> >>>> Bert Gunter >>>> >>>> "The trouble with having an open mind is that people keep coming along >>>> and sticking things into it." >>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>>> >>>> >>>> On Sun, Apr 9, 2017 at 5:38 PM, li li <hannah.hlx at gmail.com> wrote: >>>>> Hi Burt, >>>>> Yes, the function is monotone increasing and points of discontinuity are >>>>> all known. >>>>> They are all numbers between 0 and 1. Thanks very much! >>>>> Hanna >>>>> >>>>> >>>>> 2017-04-09 16:55 GMT-04:00 Bert Gunter <bgunter.4567 at gmail.com>: >>>>>> >>>>>> Details matter! >>>>>> >>>>>> 1. Are the points of discontinuity known? This is critical. >>>>>> >>>>>> 2. Can we assume monotonic increasing, as is shown? >>>>>> >>>>>> >>>>>> -- Bert >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Bert Gunter >>>>>> >>>>>> "The trouble with having an open mind is that people keep coming along >>>>>> and sticking things into it." >>>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>>>>> >>>>>> >>>>>> On Sun, Apr 9, 2017 at 1:28 PM, li li <hannah.hlx at gmail.com> wrote: >>>>>>> Dear all, >>>>>>> For a piecewise function F similar to the attached graph, I would like >>>>>>> to >>>>>>> find >>>>>>> inf{x| F(x) >=0}. >>>>>>> >>>>>>> >>>>>>> I tried to uniroot. It does not seem to work. Any suggestions? >>>>>>> Thank you very much!! >>>>>>> Hanna >>>>>>> >>>>>>> ______________________________________________ >>>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>>>>> 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. >>>>> >>>>> >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>> 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. >>> >
Hannah - sorry if this is oblique. The problem is that the question as given is ill-posed (in the mathematical sense); all the more so since there is no guarantee that the numbers that define your discontinuities can even be exactly represented in a computer. This could both be fixed if you can discretize your x-axis and accept an error on x. But without knowing more about your problem, it's hard to say how to do this correctly. B.> On Apr 10, 2017, at 11:01 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: > > Yup, she can decide. > > -- Bert > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Mon, Apr 10, 2017 at 7:56 AM, Boris Steipe <boris.steipe at utoronto.ca> wrote: >> Well - the _procedure_ will give a result. >> >> But think of f(x) = {-1; x <= 1/3 and 1; x > 1/3 >> >> What should inf{x| F(x) >= 0} be? >> What should the procedure return? >> >> >> >> >> >>> On Apr 10, 2017, at 10:38 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: >>> >>> Given what she said, how does the procedure I suggested fail? >>> >>> (Always happy to be corrected). >>> >>> -- Bert >>> Bert Gunter >>> >>> "The trouble with having an open mind is that people keep coming along >>> and sticking things into it." >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>> >>> >>> On Mon, Apr 10, 2017 at 1:57 AM, Boris Steipe <boris.steipe at utoronto.ca> wrote: >>>> Are you sure this is trivial? I have the impression the combination of an ill-posed problem and digital representation of numbers might just create the illusion that is so. >>>> >>>> B. >>>> >>>> >>>> >>>> >>>>> On Apr 10, 2017, at 12:34 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: >>>>> >>>>> Then it's trivial. Check values at the discontinuities and find the >>>>> first where it's <0 at the left discontinuity and >0 at the right, if >>>>> such exists. Then just use zero finding on that interval (or fit a >>>>> line if everything's linear). If none exists, then just find the first >>>>> discontinuity where it's > 0. >>>>> >>>>> Cheers, >>>>> Bert >>>>> >>>>> >>>>> Bert Gunter >>>>> >>>>> "The trouble with having an open mind is that people keep coming along >>>>> and sticking things into it." >>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>>>> >>>>> >>>>> On Sun, Apr 9, 2017 at 5:38 PM, li li <hannah.hlx at gmail.com> wrote: >>>>>> Hi Burt, >>>>>> Yes, the function is monotone increasing and points of discontinuity are >>>>>> all known. >>>>>> They are all numbers between 0 and 1. Thanks very much! >>>>>> Hanna >>>>>> >>>>>> >>>>>> 2017-04-09 16:55 GMT-04:00 Bert Gunter <bgunter.4567 at gmail.com>: >>>>>>> >>>>>>> Details matter! >>>>>>> >>>>>>> 1. Are the points of discontinuity known? This is critical. >>>>>>> >>>>>>> 2. Can we assume monotonic increasing, as is shown? >>>>>>> >>>>>>> >>>>>>> -- Bert >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> Bert Gunter >>>>>>> >>>>>>> "The trouble with having an open mind is that people keep coming along >>>>>>> and sticking things into it." >>>>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>>>>>> >>>>>>> >>>>>>> On Sun, Apr 9, 2017 at 1:28 PM, li li <hannah.hlx at gmail.com> wrote: >>>>>>>> Dear all, >>>>>>>> For a piecewise function F similar to the attached graph, I would like >>>>>>>> to >>>>>>>> find >>>>>>>> inf{x| F(x) >=0}. >>>>>>>> >>>>>>>> >>>>>>>> I tried to uniroot. It does not seem to work. Any suggestions? >>>>>>>> Thank you very much!! >>>>>>>> Hanna >>>>>>>> >>>>>>>> ______________________________________________ >>>>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>>>>>> 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. >>>>>> >>>>>> >>>>> >>>>> ______________________________________________ >>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>>> 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. >>>> >>
Er, 1/3, of course? (assuming that F is f). The infimum of a set is not necessarily a member of the set. -pd> On 10 Apr 2017, at 16:56 , Boris Steipe <boris.steipe at utoronto.ca> wrote: > > Well - the _procedure_ will give a result. > > But think of f(x) = {-1; x <= 1/3 and 1; x > 1/3 > > What should inf{x| F(x) >= 0} be? > What should the procedure return? > > > > > >> On Apr 10, 2017, at 10:38 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: >> >> Given what she said, how does the procedure I suggested fail? >> >> (Always happy to be corrected). >> >> -- Bert >> Bert Gunter >> >> "The trouble with having an open mind is that people keep coming along >> and sticking things into it." >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >> >> >> On Mon, Apr 10, 2017 at 1:57 AM, Boris Steipe <boris.steipe at utoronto.ca> wrote: >>> Are you sure this is trivial? I have the impression the combination of an ill-posed problem and digital representation of numbers might just create the illusion that is so. >>> >>> B. >>> >>> >>> >>> >>>> On Apr 10, 2017, at 12:34 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: >>>> >>>> Then it's trivial. Check values at the discontinuities and find the >>>> first where it's <0 at the left discontinuity and >0 at the right, if >>>> such exists. Then just use zero finding on that interval (or fit a >>>> line if everything's linear). If none exists, then just find the first >>>> discontinuity where it's > 0. >>>> >>>> Cheers, >>>> Bert >>>> >>>> >>>> Bert Gunter >>>> >>>> "The trouble with having an open mind is that people keep coming along >>>> and sticking things into it." >>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>>> >>>> >>>> On Sun, Apr 9, 2017 at 5:38 PM, li li <hannah.hlx at gmail.com> wrote: >>>>> Hi Burt, >>>>> Yes, the function is monotone increasing and points of discontinuity are >>>>> all known. >>>>> They are all numbers between 0 and 1. Thanks very much! >>>>> Hanna >>>>> >>>>> >>>>> 2017-04-09 16:55 GMT-04:00 Bert Gunter <bgunter.4567 at gmail.com>: >>>>>> >>>>>> Details matter! >>>>>> >>>>>> 1. Are the points of discontinuity known? This is critical. >>>>>> >>>>>> 2. Can we assume monotonic increasing, as is shown? >>>>>> >>>>>> >>>>>> -- Bert >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Bert Gunter >>>>>> >>>>>> "The trouble with having an open mind is that people keep coming along >>>>>> and sticking things into it." >>>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>>>>> >>>>>> >>>>>> On Sun, Apr 9, 2017 at 1:28 PM, li li <hannah.hlx at gmail.com> wrote: >>>>>>> Dear all, >>>>>>> For a piecewise function F similar to the attached graph, I would like >>>>>>> to >>>>>>> find >>>>>>> inf{x| F(x) >=0}. >>>>>>> >>>>>>> >>>>>>> I tried to uniroot. It does not seem to work. Any suggestions? >>>>>>> Thank you very much!! >>>>>>> Hanna >>>>>>> >>>>>>> ______________________________________________ >>>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>>>>> 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. >>>>> >>>>> >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>> 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. >>> > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
Analytically speaking. But we are (presumably) looking for a numerical algorithm, and that is constrained by numerical accuracy, and in that realm we have 0.3333333333333333148296 on the left, and 0.3333333333333333703408 on the right. And the left-side representable number is what gets returned for x <- 1/3. Whether this number, which is less than the defined discontinuity, is a correct solution depends on aspects of the problem that have not been disclosed. No? B.> On Apr 10, 2017, at 1:15 PM, Peter Dalgaard <pdalgd at gmail.com> wrote: > > Er, 1/3, of course? (assuming that F is f). The infimum of a set is not necessarily a member of the set. > > -pd > >> On 10 Apr 2017, at 16:56 , Boris Steipe <boris.steipe at utoronto.ca> wrote: >> >> Well - the _procedure_ will give a result. >> >> But think of f(x) = {-1; x <= 1/3 and 1; x > 1/3 >> >> What should inf{x| F(x) >= 0} be? >> What should the procedure return? >> >> >> >> >> >>> On Apr 10, 2017, at 10:38 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: >>> >>> Given what she said, how does the procedure I suggested fail? >>> >>> (Always happy to be corrected). >>> >>> -- Bert >>> Bert Gunter >>> >>> "The trouble with having an open mind is that people keep coming along >>> and sticking things into it." >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>> >>> >>> On Mon, Apr 10, 2017 at 1:57 AM, Boris Steipe <boris.steipe at utoronto.ca> wrote: >>>> Are you sure this is trivial? I have the impression the combination of an ill-posed problem and digital representation of numbers might just create the illusion that is so. >>>> >>>> B. >>>> >>>> >>>> >>>> >>>>> On Apr 10, 2017, at 12:34 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote: >>>>> >>>>> Then it's trivial. Check values at the discontinuities and find the >>>>> first where it's <0 at the left discontinuity and >0 at the right, if >>>>> such exists. Then just use zero finding on that interval (or fit a >>>>> line if everything's linear). If none exists, then just find the first >>>>> discontinuity where it's > 0. >>>>> >>>>> Cheers, >>>>> Bert >>>>> >>>>> >>>>> Bert Gunter >>>>> >>>>> "The trouble with having an open mind is that people keep coming along >>>>> and sticking things into it." >>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>>>> >>>>> >>>>> On Sun, Apr 9, 2017 at 5:38 PM, li li <hannah.hlx at gmail.com> wrote: >>>>>> Hi Burt, >>>>>> Yes, the function is monotone increasing and points of discontinuity are >>>>>> all known. >>>>>> They are all numbers between 0 and 1. Thanks very much! >>>>>> Hanna >>>>>> >>>>>> >>>>>> 2017-04-09 16:55 GMT-04:00 Bert Gunter <bgunter.4567 at gmail.com>: >>>>>>> >>>>>>> Details matter! >>>>>>> >>>>>>> 1. Are the points of discontinuity known? This is critical. >>>>>>> >>>>>>> 2. Can we assume monotonic increasing, as is shown? >>>>>>> >>>>>>> >>>>>>> -- Bert >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> Bert Gunter >>>>>>> >>>>>>> "The trouble with having an open mind is that people keep coming along >>>>>>> and sticking things into it." >>>>>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>>>>>> >>>>>>> >>>>>>> On Sun, Apr 9, 2017 at 1:28 PM, li li <hannah.hlx at gmail.com> wrote: >>>>>>>> Dear all, >>>>>>>> For a piecewise function F similar to the attached graph, I would like >>>>>>>> to >>>>>>>> find >>>>>>>> inf{x| F(x) >=0}. >>>>>>>> >>>>>>>> >>>>>>>> I tried to uniroot. It does not seem to work. Any suggestions? >>>>>>>> Thank you very much!! >>>>>>>> Hanna >>>>>>>> >>>>>>>> ______________________________________________ >>>>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>>>>>> 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. >>>>>> >>>>>> >>>>> >>>>> ______________________________________________ >>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>>> 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. >>>> >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Office: A 4.23 > Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com > > > > > > > > >
Well, I haven't checked carefully, but of course this does not find infs or sups at all, just mins or maxes in the sample, which are not the same. You'll have to do your own full testing and debugging, however. I do not provide such a service. -- Bert [[alternative HTML version deleted]]
Yes. If the function f takes the value zero at some discontinuity point, then the code gives the inf of the set I described. Otherwise, it is an approximation since we need to worry about numerical accuracy. 2017-04-10 14:08 GMT-04:00 Bert Gunter <bgunter.4567 at gmail.com>:> Well, I haven't checked carefully, but of course this does not find infs > or sups at all, just mins or maxes in the sample, which are not the same. > > You'll have to do your own full testing and debugging, however. I do not > provide such a service. > > -- Bert > > >[[alternative HTML version deleted]]
Here's my crossword-puzzle for the day: # A sample monotonous discontinuous function with a single root # (vectorized) F <- function(x) { return((as.numeric(x >= 0.112233445566778899) * 2) - 1) } discRoot <- function(xL, xR, F, k = 10) { # Return the interval containing a single root of the monotonous # increasing function F() in the range [xL, xR] to k-digits # accuracy. myK <- 1 while (myK <= k) { x <- seq(xL, xR, length.out = 11) # ten intervals y <- F(x) # evaluate F i <- min(which(y >= 0)) # find index of first positive y xR <- x[i] # make this the right bound xL <- x[max((i - 1), 1)] # left bound, but prevent xL < 1 myK <- myK + 1 # increase resolution } return(c(xL, xR)) } R > print(discRoot(0, 1, F), digits = 22) [1] 0.1122334455000000147384 0.1122334456000000091347 R > print(discRoot(0, 1, F, k = 5), digits = 22) [1] 0.1122300000000000103073 0.1122400000000000064304 R > print(discRoot(0, 1, F, k = 15), digits = 22) [1] 0.1122334455667780145349 0.1122334455667790137356 R > print(discRoot(0, 1, F, k = 22), digits = 22) [1] 0.1122334455667788888356 0.1122334455667789027133 R > print(discRoot(0, 1, F, k = 30), digits = 22) [1] 0.1122334455667788888356 0.1122334455667789027133 Try it on your own function Cheers, B.> On Apr 10, 2017, at 1:53 PM, li li <hannah.hlx at gmail.com> wrote: > > Here are the codes again. I made an error in the previous email. > Thanks very much. > > > ##points of discontinuity > pts <- seq(0,1,by=0.2) > n <- length(pts) > > > ##g is the step function > g <- function(x){ > val <- numeric(n) > for (i in 1:(n-1)){val[i] <- pts[i]*((x>=pts[i])&&(pts[i+1])>x)} > val[n] <- pts[n]*(x>=pts[n]) > sum(val)} > ##f is the piecewise function > f <- function(x){x+g(x)-1} > > ##values of f at the discontinuity points > z <- pts > for (i in 1:n){z[i]<- f(pts[i])} > > ##find the root > > if(any(z==0)=="TRUE") { > res <- pts[which(z==0)] > } else { > l <- pts[max(which(z<0))] > r <- pts[min(which(z>0))] > res <- uniroot(f, c(l,r))$root > } > > ##check the root > > f(res) > > > 2017-04-10 13:41 GMT-04:00 li li <hannah.hlx at gmail.com>: > Hi Burt and all, > Thanks so much for your reply. > Here is an example. > Consider the points (0, 0.2, 0.4, 0.6, 0.8,1) and denote them as c_1, ..., c_5. > The piecewise function is defined as f(x)=x+g(x)-1, x >=0, where > g is a step function defined as follows: > > <image.png> > > Below is the code to find inf{x | f(x) >=0} according to your suggestion. > If there is any suggestion to make the code simpler, please let me know. > Thanks so much for your help. > Hannah > > > > > ##points of discontinuity > pts <- seq(0,1,by=0.2) > n <- length(pts) > > > ##g is the step function > g <- function(x){ > val <- numeric(n) > for (i in 1:(n-1)){val[i] <- pts[i]*((x>=pts[i])&&(pts[i+1])>x)} > val[n] <- pts[n]*(x>=pts[n]) > sum(val)} > ##f is the piecewise function > f <- function(x){x+g(x)-1} > > ##values of f at the discontinuity points > z <- pts > for (i in 1:n){z[i]<- f(pts[i])} > > ##find the root > > if(any(z==0)=="TRUE") { > res <- pts[max(which(z==0))] > } else { > l <- pts[max(which(z<0))] > r <- pts[min(which(z>0))] > res <- uniroot(f, c(l,r))$root > } > > ##check the root > > f(res) > > Hanna > >