Can I solve for multiple variables in an equation?
Show older comments
I have
vcuaamo = 13.58823529;
sjuaamo = -4.470588235;
vcuhome = 19.125;
sjuhome = -2.111111111;
vcuaway = 8.666666667;
sjuaway = -7.125;
vculast7 = 15.57142857;
sjulast7 = 2.714285714;
vcuprepoints = 71.9;
sjuprepoints = 65.7;
form = 12
abcd = randfixedsum(4,1,1,0,2)
dcba = sort(abcd,'descend')
a = dcba(1,1), b = dcba(2,1), c = dcba(3,1), d = dcba(4,1)
prediction = (vcuaamo-sjuaamo)*a+(vcuhome-sjuaway)*c+(vculast7-sjulast7)*b+(vcuprepoints-sjuprepoints)*d
randfixed sum just gives me a 4x1 matrix of random numbers between 0-2 that add up to equal 1 (because i needed 4 random variables to equal 1).
I would like to solve for what combo of a,b,c,d equals 12. Is there anyway to do that?
Answers (1)
John D'Errico
on 10 Mar 2019
Edited: John D'Errico
on 11 Mar 2019
Sigh. It looks like this is a followup to your last question. But it is COMPLETELY different. And you cannot use randfixedsum, which applied to the question as you posed it before. Change the question, and you cannot just use the last answer. Sorry, but it does not work that way.
Now, you are apparently asking for a set of "random" numbers, such that...
a + b + c + d = 1
(vcuaamo-sjuaamo)*a+(vcuhome-sjuaway)*c+(vculast7-sjulast7)*b+(vcuprepoints-sjuprepoints)*d == 12
a >= b*c*d
b >= c*d
Where...
vcuaamo-sjuaamo
ans =
18.058823525
vcuhome-sjuaway
ans =
26.25
vculast7-sjulast7
ans =
12.857142856
vcuprepoints-sjuprepoints
ans =
6.2
So the second equality reduces to
18.058823525*a + 12.857142856*b + 26.25*c + 6.2*d == 12
Is that now your goal? Will there be other changes later, so I'll be chasing a moving target?
Here are a set of numbers, as the rows of abcd. See that each row of numbers satisfies all of your requirements.
abcd
abcd =
0.471705866365957 0.0132926640255532 0.00586694322713018 0.509134526381359
0.346155290576649 0.0793275924323071 0.0582000190305242 0.51631709796052
0.206800938580258 0.155886157573227 0.115203378769798 0.522109525076716
0.34861314533669 0.129921911760084 0.0399476061967838 0.481517336706442
0.419550109712593 0.10999136195574 0.00460853264631487 0.465849995685353
0.315940580622874 0.0977203799366216 0.0699639840811281 0.516375055359376
0.312054299604144 0.291064651694339 0.00806704060428341 0.388814008097233
0.323553078479239 0.0824424061823778 0.0705341778551503 0.523470337483233
0.330141930351684 0.152636044152945 0.0433309306162425 0.473891094879129
0.450907712422767 0.0236539907983886 0.0147280307460139 0.510710266032831
a = abcd(:,1);b = abcd(:,2);c = abcd(:,3);d = abcd(:,4);
a+b+c+d
ans =
1
1
1
1
1
1
1
1
1
1
a > b.*c.*d
ans =
10×1 logical array
1
1
1
1
1
1
1
1
1
1
b > c.*d
ans =
10×1 logical array
1
1
1
1
1
1
1
1
1
1
abcd*[18.058823525 12.857142856 26.25 6.2]'
ans =
12
12
12
12
12
12
12
12
12
12
Is that what you need?
7 Comments
Hunter Herrenkohl
on 11 Mar 2019
Walter Roberson
on 11 Mar 2019
(My solutions did not meet the sum criteria)
John D'Errico
on 11 Mar 2019
In fact, I find the problem becomes more interesting yet. The method I used to generate solutions is also flawed, in the sense that it does not generate all possible solutions. I had relied on Walter's idea in one respect, that we needed a > b, and at least a partial sort of the numbers. Yet, for example, the following set of numbers meets the simple sum constraints and the product constraints:
[a,b,c,d] == [0.2 0.3 0.001 0.499]
So we meet the constraints that
a + b + c + d = 1
a > b*c*d
b > c*d
I'd assume it does not meet the requirement:
8.058823525*a + 12.857142856*b + 26.25*c + 6.2*d == 12
since I did not create it to do so. Regardless, this means that the solution locus of ALL numbers that satisfy the requirements is somewhat complex, since the boundaries of the feasible set are nonlinear. Sampling uniformly over that complete set is not trivial. It is still solvable as a general problem.
Ugh. I'll do a little writing, some coding, and return in an hour or so.
Walter Roberson
on 11 Mar 2019
Are those product constraints? I thought a>bcd was short form for a>b & a>c & a>d
John D'Errico
on 11 Mar 2019
Edited: John D'Errico
on 11 Mar 2019
Hmm. A VERY interesting interpretation! Funny, I guess, in that I just assumed it meant a product. But either might be true.
I guess I need to know that myself. I don't think we can answer these questions without knowing which it is.
Hunter Herrenkohl
on 12 Mar 2019
Walter Roberson
on 12 Mar 2019
Under the constraint a > 0, b > 0, c > 0, d > 0, a > b, a > c, a > d, b > c, b > d, c > d, then there does not appear to be solutions. The lowest prediction value appears to be approximately 15.48 under those constraints.
Categories
Find more on Parallel Computing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!