Hi, I'm trying to find a way to determine what multiples of the combination of three or more numbers equals a forth number. So, if I had a number set like: c(13.4689, 12.85212, 17.05071) What combination and multiples of these numbers would average to 15.0078? (so, something that would tell me x, y, and z in (x*13.4689 + y*12.85212+ z*17.05071) / x+y+z) = 15.0078 I think this is doable with aggregate? [[alternative HTML version deleted]]
Solve for one of your variables and it will be given in terms of the other two. That is, there is a whole infinite plane of solutions. No, aggregate will not be sufficient to enumerate the solution set.. -- Sent from my phone. Please excuse my brevity. On December 7, 2017 10:37:37 PM PST, Benjamin Sabatini <sunscape1 at hotmail.com> wrote:>Hi, > >I'm trying to find a way to determine what multiples of the combination >of three or more numbers equals a forth number. > >So, if I had a number set like: > >c(13.4689, 12.85212, 17.05071) > >What combination and multiples of these numbers would average to >15.0078? (so, something that would tell me x, y, and z in (x*13.4689 + >y*12.85212+ z*17.05071) / x+y+z) = 15.0078 > >I think this is doable with aggregate? > > [[alternative HTML version deleted]]This is a plain text mailing list. Please learn how to use your email program.> >______________________________________________ >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.
Are x,y, and z supposed to be positive whole numbers? If so, there may be no solutions. If there is a solution set, of course any multiple of the set is a solution set, so presumably you want a minimal set in some sense. This strikes me as a hard problem mathematically, but maybe there is some obvious way to set an upper bound on a minimal x,y, and z, in which case a simple grid search could then be used. Naturally, if any real numbers are sought, Jeff is correct. 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 Fri, Dec 8, 2017 at 12:19 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> Solve for one of your variables and it will be given in terms of the other > two. That is, there is a whole infinite plane of solutions. No, aggregate > will not be sufficient to enumerate the solution set.. > -- > Sent from my phone. Please excuse my brevity. > > On December 7, 2017 10:37:37 PM PST, Benjamin Sabatini < > sunscape1 at hotmail.com> wrote: > >Hi, > > > >I'm trying to find a way to determine what multiples of the combination > >of three or more numbers equals a forth number. > > > >So, if I had a number set like: > > > >c(13.4689, 12.85212, 17.05071) > > > >What combination and multiples of these numbers would average to > >15.0078? (so, something that would tell me x, y, and z in (x*13.4689 + > >y*12.85212+ z*17.05071) / x+y+z) = 15.0078 > > > >I think this is doable with aggregate? > > > > [[alternative HTML version deleted]] > > This is a plain text mailing list. Please learn how to use your email > program. > > > > >______________________________________________ > >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. >[[alternative HTML version deleted]]
Please keep all replies onlist if there is no reason to keep them private. I am not a free, private consultant (and so might choose to ignore your followups); and I don't have all or necessarily the best answers anyway. So give yourself the maximal chance to be helped by others. Anyway, ?expand.grid is what you're looking for I think as an alternative to nested loops. If "results" is a vector of calculated results, i.e. the averages for the grid of combinations you generate, and "target" is your desired target (average), here of 15.0078, then which.min(abs(results - target)) gives you the index of the closest results and abs(results - target) < tol gives you a vector of logicals of results that are within tol of the target. This is all pretty basic stuff, which suggests that you really need to spend some time with an R tutorial or two. Here are some suggestions, but a web search would uncover many more, some of which might be more suitable for you: https://www.rstudio.com/online-learning/#R This list can help (not sure if I did here), but it cannot replace such homework on your own. 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 Fri, Dec 8, 2017 at 9:15 AM, Benjamin Sabatini <sunscape1 at hotmail.com> wrote:> Hi, > > Yes, actually, I could set an upper limit and grind through the > possibilities to find a minimal set or a few if that's what you mean. Close > to the result would be OK, too. Otherwise it would go on forever, I > suppose. > > At first I was thinking of just trying to write three for loops to test > for every set of the multiples of x, y, and z between something like 1 and > 10,000, but I understand that this is not at all efficient in R. So, (1*13.4689 > + 1*12.85212+ 1*17.05071) / 1+1+1), (1*13.4689 + 2*12.85212+ 1*17.05071) > / 1+2+1)... > > Is there a better way? If I solve for z is it then easier with an upper > limit? So, z = x*0.753288 + y*1.0552 > and then loop it? > > ------------------------------ > *From:* Bert Gunter <bgunter.4567 at gmail.com> > *Sent:* Friday, December 8, 2017 3:16 PM > *To:* Jeff Newmiller > *Cc:* R-help; Benjamin Sabatini > *Subject:* Re: [R] trying to find the multiple combinations... > > Are x,y, and z supposed to be positive whole numbers? If so, there may be > no solutions. If there is a solution set, of course any multiple of the set > is a solution set, so presumably you want a minimal set in some sense. This > strikes me as a hard problem mathematically, but maybe there is some > obvious way to set an upper bound on a minimal x,y, and z, in which case a > simple grid search could then be used. > > Naturally, if any real numbers are sought, Jeff is correct. > > 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 Fri, Dec 8, 2017 at 12:19 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> > wrote: > > Solve for one of your variables and it will be given in terms of the other > two. That is, there is a whole infinite plane of solutions. No, aggregate > will not be sufficient to enumerate the solution set.. > -- > Sent from my phone. Please excuse my brevity. > > On December 7, 2017 10:37:37 PM PST, Benjamin Sabatini < > sunscape1 at hotmail.com> wrote: > >Hi, > > > >I'm trying to find a way to determine what multiples of the combination > >of three or more numbers equals a forth number. > > > >So, if I had a number set like: > > > >c(13.4689, 12.85212, 17.05071) > > > >What combination and multiples of these numbers would average to > >15.0078? (so, something that would tell me x, y, and z in (x*13.4689 + > >y*12.85212+ z*17.05071) / x+y+z) = 15.0078 > > > >I think this is doable with aggregate? > > > > [[alternative HTML version deleted]] > > This is a plain text mailing list. Please learn how to use your email > program. > > > > >______________________________________________ > >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/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >[[alternative HTML version deleted]]
As Burt and Jeff stated that there is an infinite set of solutions. If you are interested in a particular solution, such as getting 15.0078, you can easily achieve that by trial and error; that is fix 1 or 2 variables and change the the rest till you get the desired solution. I tried that and came up with the same solution as you listed. if you are interested in a set of solutions within a tolerance, then that will be a different story. HTH EK On Fri, Dec 8, 2017 at 1:37 AM, Benjamin Sabatini <sunscape1 at hotmail.com> wrote:> Hi, > > I'm trying to find a way to determine what multiples of the combination of > three or more numbers equals a forth number. > > So, if I had a number set like: > > c(13.4689, 12.85212, 17.05071) > > What combination and multiples of these numbers would average to 15.0078? > (so, something that would tell me x, y, and z in (x*13.4689 + y*12.85212+ > z*17.05071) / x+y+z) = 15.0078 > > I think this is doable with aggregate? > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Off topic, but for the record... As Jeff already noted,the equation reduces to a single linear equation with rational coefficients, so of course there are infinitely many integer solutions. Apologies for my dummheit. -- Bert On Fri, Dec 8, 2017 at 9:47 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote:> Please keep all replies onlist if there is no reason to keep them private. > I am not a free, private consultant (and so might choose to ignore your > followups); and I don't have all or necessarily the best answers anyway. So > give yourself the maximal chance to be helped by others. > > Anyway, > > ?expand.grid is what you're looking for I think as an alternative to > nested loops. If "results" is a vector of calculated results, i.e. the > averages for the grid of combinations you generate, and "target" is your > desired target (average), here of 15.0078, then > > which.min(abs(results - target)) > gives you the index of the closest results and > > abs(results - target) < tol > gives you a vector of logicals of results that are within tol of the > target. > > This is all pretty basic stuff, which suggests that you really need to > spend some time with an R tutorial or two. Here are some suggestions, but > a web search would uncover many more, some of which might be more suitable > for you: > https://www.rstudio.com/online-learning/#R > > This list can help (not sure if I did here), but it cannot replace such > homework on your own. > > 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 Fri, Dec 8, 2017 at 9:15 AM, Benjamin Sabatini <sunscape1 at hotmail.com> > wrote: > >> Hi, >> >> Yes, actually, I could set an upper limit and grind through the >> possibilities to find a minimal set or a few if that's what you mean. Close >> to the result would be OK, too. Otherwise it would go on forever, I >> suppose. >> >> At first I was thinking of just trying to write three for loops to test >> for every set of the multiples of x, y, and z between something like 1 and >> 10,000, but I understand that this is not at all efficient in R. So, (1*13.4689 >> + 1*12.85212+ 1*17.05071) / 1+1+1), (1*13.4689 + 2*12.85212+ 1*17.05071) >> / 1+2+1)... >> >> Is there a better way? If I solve for z is it then easier with an upper >> limit? So, z = x*0.753288 + y*1.0552 >> and then loop it? >> >> ------------------------------ >> *From:* Bert Gunter <bgunter.4567 at gmail.com> >> *Sent:* Friday, December 8, 2017 3:16 PM >> *To:* Jeff Newmiller >> *Cc:* R-help; Benjamin Sabatini >> *Subject:* Re: [R] trying to find the multiple combinations... >> >> Are x,y, and z supposed to be positive whole numbers? If so, there may be >> no solutions. If there is a solution set, of course any multiple of the set >> is a solution set, so presumably you want a minimal set in some sense. This >> strikes me as a hard problem mathematically, but maybe there is some >> obvious way to set an upper bound on a minimal x,y, and z, in which case a >> simple grid search could then be used. >> >> Naturally, if any real numbers are sought, Jeff is correct. >> >> 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 Fri, Dec 8, 2017 at 12:19 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us >> > wrote: >> >> Solve for one of your variables and it will be given in terms of the >> other two. That is, there is a whole infinite plane of solutions. No, >> aggregate will not be sufficient to enumerate the solution set.. >> -- >> Sent from my phone. Please excuse my brevity. >> >> On December 7, 2017 10:37:37 PM PST, Benjamin Sabatini < >> sunscape1 at hotmail.com> wrote: >> >Hi, >> > >> >I'm trying to find a way to determine what multiples of the combination >> >of three or more numbers equals a forth number. >> > >> >So, if I had a number set like: >> > >> >c(13.4689, 12.85212, 17.05071) >> > >> >What combination and multiples of these numbers would average to >> >15.0078? (so, something that would tell me x, y, and z in (x*13.4689 + >> >y*12.85212+ z*17.05071) / x+y+z) = 15.0078 >> > >> >I think this is doable with aggregate? >> > >> > [[alternative HTML version deleted]] >> >> This is a plain text mailing list. Please learn how to use your email >> program. >> >> > >> >______________________________________________ >> >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/posti >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> >> >[[alternative HTML version deleted]]
Possibly Parallel Threads
- trying to find the multiple combinations...
- trying to find the multiple combinations...
- Integration of vector syntax unknown
- find bayesian information criterion for all variable combinations
- [nut] usbhid-ups: trailing spaces in nut-scanner output not ignored when trying to find ups (#26)