cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

A Programme works out all the possible answers?

h_nas
4-Participant

A Programme works out all the possible answers?

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

6 REPLIES 6
AlanStevens
17-Peridot
(To:h_nas)

If you just mean positive integers it's trivial:

ten.PNG

or have I misunderstood what you are looking for?

Alan

h_nas
4-Participant
(To:AlanStevens)

What if I have a, b, c, d and e?

AlanStevens
17-Peridot
(To:h_nas)

Here's a brute force and ignorance method, again assuming positive integers only.

ten2.PNG

Alan

h_nas
4-Participant
(To:AlanStevens)

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!

Werner_E
25-Diamond I
(To:h_nas)

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

Fred_Kohlhepp
23-Emerald I
(To:h_nas)

Are you placing bounds on a and b? Integers, fine. Positive? Or are negative values allowed? Count "0" as an integer?

Announcements

Top Tags