+2  A: 

Please use Maple, Mathcad or Sage for that. Here is a list of software, that can help you with it: http://en.wikipedia.org/wiki/Comparison_of_computer_algebra_systems

FractalizeR
What are you saying - I need to purchase some software product - that's not what I had in mind.
Mark
@Mark, no. What FractalizeR suggests is to use a CAS for this. If you'd taken the time to actually click (or read) the link s/he posted, you would have noticed that there are many free products available. It may not be the answer you're looking for, but that doesn't mean it's a perfectly legit answer.
Bart Kiers
Just to be clear, I don't have an isolated math problem I'm trying to solve (for homework or otherwise). I was looking to write code to solve the above, if these are API's or similar then of course that would work. Was hoping someone would give a brief verbal overview of the solution. AakashM did mention Diophantine equations, after of course inexplicably slamming me for posting something off-topic, so I will at least check into Diophantine equations in a moment.
Mark
But anyway, diopantine, CAS - probably enough to get me going here, so thanks to all.
Mark
+3  A: 
Unreason
The api lp_solve mentioned in the wikipedia article looked promising until I read the following in the documentation: "Also note that both objective function and constraints must be linear equations. This means that no variables can be multiplied with each other." So as you say, what I'm doing is non-linear. Specifically its "Mixed Integer Nonlinear Programming (MINLP)", a term I discovered just now: "[It] refers to mathematical programming with continuous and discrete variables and nonlinearities in the objective function and constraints."
Mark
except in my case only the objective function is nonlinear
Mark
@Mark, updated the answer
Unreason
Thanks for pointing out that the original objective formula can be rewritten as summation(abs((s*tk)-ck). "So all C = 1, and all t and s → ∞ for which your original expression approaches n." Its only your conclusion here I believe that is incorrect. C1..Cn are constant. I cannot assume some value for them though. I've edited the OP, btw.
Mark
Also C1...Cn will all be different sizes;
Mark
@Mark, I updated the answer with some corrections and further explained the conclusions.
Unreason
@Mark, I think I'll write a new answer - my whole answer is looking for maximum, and in your question you are looking for minimum. :/
Unreason
@Mark, ok, I hope I got it right this time. :)
Unreason
To use a specific example, Here are C1..Cn (where n = 6). 71.998200, 395.611121, 430.776584, 376.772482, 394.355213, 296.394365. There is a maximum size for a tk of 127,so what I do currently is take the largest C which is 430.776584 and divide by 127 to get the scaling factor s = 3.391941. And so if C1 is 430.776584 then t1 is 127. And t1*s yields C1 exactly. But all the other t's when multiplied by s will be off from their corresponding C by some small percentage (small but still noticeable). But anyway, can you put your solution in the above context.
Mark
But at any rate, I think I may have it now - I had misread the operator precedence of the expression Nk/Dk * 1Dk. But if you want to give an answer to the above that might be helpful.
Mark
The thing about rational numbers concerned me for a moment (since you brought it up), but then I realized any limited precision number is rational.
Mark
But you said that yourself.
Mark
Still thinking out loud, using my example above, I think I see some problems:You would have 430776584/1000000,395611121/1000000 [etc.] for C1..Cn. and the largest common denominator is 1000000 but that leaves t's that are much too large. I augmented the OP yesterday to note that there is a maximum size for each t. But I have to get some sleep and will come back to this later. Thanks.
Mark
@Mark, thinking out loud: well the above solution finds the perfect set of integers. If you need to scale them down to acceptable domain you should divide them with some number. Finding the biggest common denominator on the solution (and not in the middle of the process) would be give minimal integers that are still a perfect solution. If that is still not within desired range you will have to live with some discrepancy. Can you edit the question again and explain the goal function (explain it in terms of element sizes and page size, etc...)
Unreason
+1  A: 

I think that unreason gave the correct answer. You need to read a book about "Nonlinear Integer Programming". I don't have a good book to recommend you, but you can probably find something by going to the library.

I don't think that lp_solve is not good enough for you, because you cannot rewrite your problem in to a mixed integer Integer linear Programming problem (MILP). Maple and Mathcad is not a good idea, because you are not looking for symbolic algebra package.

My guess us that the book will tell you to do branch and bound. Here is a schematic description:

1) Start out solving a generalized problem where t_k are all real prsitime numbers

minimize Σnk = 1 (1 - min(s·tk,Ck)/max(s·tk,Ck)), under the constrain that s > 0, t1…tn ∈ R+

.You can use a generalized Newtons method to do this. Matlab and scipy provide generalized solvers this out of the box, but be careful because your function may have several local minima.

2) Once you have found this solution, you can do a branch ing step. Choose a variables t_k and an integer number a_k, and solve the following two problems independently

Problem 1 minimize Σnk = 1 (1 - min(s·tk,Ck)/max(s·tk,Ck)), under the constrain that s > 0, t1…tn ∈ R+and t_k <= a_k

Problem 2 minimize Σnk = 1 (1 - min(s·tk,Ck)/max(s·tk,Ck)), under the constrain that s > 0, t1…tn ∈ R+ and t_k >= a_k

3) Keep doing branching steps until you have split your problem in to a set of sub-problems that each have an integer solution. Then you can compare these integer solutions and choose the best one.

As you probably have guessed this description is somewhat schematic. You need good branching rules to branch the correct way, and you need good bounding rules to avoid following branches that arent promising.

nielsle
"branch and bound" is a term I keep on encountering as well so thanks
Mark
actually my solution was completely wrong, but I think it might be right now.
Unreason
Unreasons fourth solution looks correct. That was a nice trick. In the special case where all the numbers C_k are decimal numbers with n decimals then he gets s=10^-n and t_k=C_k*10^n.
nielsle