Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
Hi,
I need some ideas on how to do the following:
I have two variables a and b, the sum of a & b is 10. I would like Mathcad to work out all the possibilities that give me a+b=10, and a keep in mind I would like them to be integers.
Thank you
If you just mean positive integers it's trivial:
or have I misunderstood what you are looking for?
Alan
What if I have a, b, c, d and e?
Here's a brute force and ignorance method, again assuming positive integers only.
Alan
Thank you, The brute force is working:)
Just for the fun of it, insteade of 9 use 99!
I am using Mathcad Prime and still runing around without result!
HinndNaser wrote:
Thank you, The brute force is working:)
Just for the fun of it, insteade of 9 use 99!
I am using Mathcad Prime and still runing around without result!
It sure will be hard to find 99 numbers in the range of 1 to 9 which sum up to 10
Why not post the real problem you are working on? But whatever its is, Mathcad provides no clever algorithms to deal with integers, diophantic equations or number theory in general. So brute force seems to be a quick and dirty option, but with a lot of values to deal with and probably a wider range per variable, its not an option still anymore as it will take more time than you are willing and able to spend. So the problem might be solveable by an approach unique to that specific problem.
In case you are interested in a way to write a routine with an arbitrary number of variables on not a static number of nested for loops, take a look at the routine I posted here: http://communities.ptc.com/message/199660#199660
The routine sure could be modified to solve tasks as your with a variable number of arguments, arbitrary function s (not only summation of all arguments) and a target value (like th 10 in your example).
But it will very soon get too slow to be helpful.
You may also be interested in this thread: http://communities.ptc.com/message/194291#194291
Are you placing bounds on a and b? Integers, fine. Positive? Or are negative values allowed? Count "0" as an integer?