Skip to main content
1-Visitor
January 4, 2013
Solved

Solve strange equation.........

  • January 4, 2013
  • 21 replies
  • 8285 views

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.

Best answer by Werner_E

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?

eq1.png

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.


21 replies

1-Visitor
January 4, 2013

I would think that this is a simpler version of this problem:

http://communities.ptc.com/message/193969#193969

Werner_E
25-Diamond I
January 4, 2013

Roger Yeh schrieb:

I would think that this is a simpler version of this problem:

http://communities.ptc.com/message/193969#193969

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.

Werner_E
Werner_E25-Diamond IAnswer
25-Diamond I
January 4, 2013

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?

eq1.png

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.


jkowalski1-VisitorAuthor
1-Visitor
January 5, 2013

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.

Werner_E
25-Diamond I
January 5, 2013

Some other possibilities attached

3-Newcomer
January 6, 2013

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 12427
1 1 22327
1 1 32227

...

23 1 2 127
23 2 1 127
24 1 1 127

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...

Werner_E
25-Diamond I
January 7, 2013

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