Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
hello.
Just calculate all the numbers satisfying the equation.
I do not even know for how this August to take. Can do it iteratively.
Help please
See atached file.
Solved! Go to Solution.
Just calculate all the numbers satisfying the equation.
I do not even know for how this August to take. Can do it iteratively.
"how this August to take" ??? What on earth does Google translate try to tell us? 😉
Where did you get this task from?
You are looking for something like this?
You failed with the solve block as you need guess values (see attached) but even then the solve block does not work correctly. Its useless for this kind of task.
I would think that this is a simpler version of this problem:
Roger Yeh schrieb:
I would think that this is a simpler version of this problem:
Yes, its similar. This time I went the easy way and did a brute force with just 4 nested loops. To extend it to allow for a variable number of summands would mean some extra work. Maybe it would be easier do do it recursive as I did it in the Fibonacci decomposition you pointed us to.
Just calculate all the numbers satisfying the equation.
I do not even know for how this August to take. Can do it iteratively.
"how this August to take" ??? What on earth does Google translate try to tell us? 😉
Where did you get this task from?
You are looking for something like this?
You failed with the solve block as you need guess values (see attached) but even then the solve block does not work correctly. Its useless for this kind of task.
hi
Google translator messed something with the word "August".Yes solve block could not solve it, I knew that.
I needed just a program that will solve it.
I know how to change your program to suit my needs.
Werner thanks. You are a master of math.
See the file.
Simple solutions are the best.
Jan Kowalski schrieb:
Simple solutions are the best.
Everything should be made as simple as possible, but not simpler [Albert Einstein]
The program is too slow. It can somehow speed up 10000 times ???????????
See File
Jan Kowalski schrieb:
The program is too slow. It can somehow speed up 10000 times ???????????
See File
Sure, wait for a quantum computer to come by 🙂
No, honestly, the kind of simple brute force which tries ALL possible combinations gets pretty slow if applied to 20 summands, like you did.
You will have to apply some tricks to reduce the number of possibilities. As written now the program checks about 5*10^35 possibilities!
You may look at http://communities.ptc.com/message/193969#193969 for some ideas. One thing which comes to mind is to break out of the for loops when its already clear that no solution could be found - because even if all coming numbers would be tens you can not reach the sum or if the sum is already greater than the disired sum. Would guess that while-loops woul do better if you intend to speed things up.
As you can see in the mentioned thread, I called the function recursive, thus avoiding the nested for-loops and that way you can make the number of summands variable. Doing without recursion would speed things up again but will result in an even more complex code.
In the end, a more speedy function sure would mean a complete redesign.
I understand what you mean. I guess I'll have to buy a supercomputer
Thanks for an explanation of the problem.
Jan Kowalski schrieb:
I understand what you mean. I guess I'll have to buy a supercomputer
Good news! You just saved a lot of money
Here is a speeded up version of "MultiMulti" - quick and dirty (and I mean really dirty!) - and an even faster and more general function. I removed the option to specify a range of desired sums but that could easily be integrated again. It may be, that it speeds up things a 10000 times (as you requested) and more in some situations, in case of the example in the screenshot its "only" about 5195 times faster. The secret is not to go any further if its clear that the desired sum can not be achieved even by taking the highest possible remaining numbers and to stop going further if the sum will greater than the desired one even if we take the lowest possible remaining numbers. That saves us quite a lot of needless attempts.
Jesus Christ the impossible became possible.I do not know what time the calculations are different.
With these values Mathcad crash.See file.gif
With these values Mathcad crash.See file.gif
Yes, same problem here with Mathcad 15 M020, so they haven't fixed it.
But you had sent the solution yourself!
Do as advised, just avoid inline evaluation and it works.
BTW, you should use the function "Zerlege" or whatever you may call it, directly and not via the timer shell.
As it seems that you are interested not in the resulting marix but in the number of columns (the number of possibilities) only, I may suggest you change the function accordingly. Should speed up things again and would make it easier to use for your purpose.
Attached is a slightly modified version which allows for a range of desired sums again.
May I ask what kind of problem you are working on that you are in need for that kind of calculations?
I found your program earlier error. See the added file. Working on a lotto system and so far without success. Because it is difficult to predict random numbers. And also I wanted to see what you have the capability of solving problems in math.
It's just easier to you comes in the programming function.
Jan Kowalski schrieb:
I found your program earlier error. See the added file. Working on a lotto system and so far without success. Because it is difficult to predict random numbers. And also I wanted to see what you have the capability of solving problems in math.
It's just easier to you comes in the programming function.
You haven't found an error, you made one 😉
I've tried to tell you so in a prior post attachment that your abscissa is wrong resp. misleading.
In your example you store the number of possible decompositions of the sum 15 in B[0], for sum 16 in B[1], etc. Then you graph these numbers over the indices of your array. That way the graph is shiftet 15 units to the left. Thats the reason your mean value does not fit.
You should either let the zeros be stored in B[0] to B[14] or let the ordinate be B[i-15.
BTW, rewriting the function "Zerlege" to return no matrix but only the numer of decompositions will speed up things by another factor of 300 to 400.
WE
Yes you are right,my mistake.
Thanks for all Werner
Jan Kowalski schrieb:
Yes you are right,my mistake.
Thanks for all Werner
No problem. I forgot to include the new file. Find it attched.
You can see that "ZerlegeAnzahl" speeds things up quite a lot if you don't need the matrix values themselves:
Good luck and big money with your lotto system!
I was busy when the email came in about this thread, and I was in MATLAB. So I threw this together...MATLAB code, but you can duplicate in Mathcad...
clc | % clear the command window |
clear all | % clear all variables |
format compact % condense command window output
T = 27
N = 30 % 2600 for T = 27, N = 30 a=0; b=0; c=0; d=0; solutions = 0; for a=1:N
if (a+b+c+d) == T
disp ([a b c d a+b+c+d]); | |
solutions = solutions + 1; | |
break; |
end
for b=1:N
if (a+b+c+d) == T | |
disp ([a b c d a+b+c+d]); | |
solutions = solutions + 1; | |
break; | |
end | |
for c=1:N | |
if (a+b+c+d) == T | |
disp ([a b c d a+b+c+d]); | |
solutions = solutions + 1; | |
break; | |
end | |
for d=1:N | |
if (a+b+c+d) == T | |
disp ([a b c d a+b+c+d]); | |
solutions = solutions + 1; | |
break; | |
end | |
end | |
end |
end
end
solutions
T =
27 |
N =
30 | |||||
1 | 1 | 1 | 24 | 27 | |
1 | 1 | 2 | 23 | 27 | |
1 | 1 | 3 | 22 | 27 |
...
23 | 1 | 2 | 1 | 27 | |
23 | 2 | 1 | 1 | 27 | |
24 | 1 | 1 | 1 | 27 |
solutions =
2600 |
Is that what you wanted? All the combinations of a,b,c,d that add to 27? Sorry for the garbage. I tried to paste plain text, and that is what I got. It ran in a second or so...
Your program ignores the stated condition that all numbers have to be different and it seems that you count the permutations of every solutions as well. Thats easy to repair by changing the for loops (a=1:N-3 b=a+1:N-2 etc.)
You may see my first function in this thread which goes exactly that simple brute force way. No problem with just 4 variables.
But then Jan rewrote my function to work with 20 summands and numbers from 1 to 80 (the latter would not have been the problem). Of course it would not finish in a lifetime.
In the meantime I arrived at a rather quick function which allows for a variable number of summands and may be given a range of desired sums, not just a single one. Follow the thread for more information.
But feel free to come up with a faster and/or more compact and straightforward solution.
WE
additional solutions never do harm and may bring some new insights.