Maple still evaluating 9 hours later: Is it my Maths, Code or PC?

Hi

I have a system of 33 equations in 33 unknowns. I figured I could use Linear Algebra and Maple to solve this system. Now nearly 9 hours later Maple is still 'Evaluating'. It's been many years since I studied Mathematics and I am very rusty since I rarely use what I learned directly in my job.

Also this is my first attempt at using Maple so please be gentle if you see a ridiculously stupid mistake :-)

I'm wondering if it is my Maths, my code or my PC specs (1.7 GHz Intel Pentium M, 512 MB RAM) that is causing Maple to take so long to 'Evaluate' or is this normal?

Here's the Maths I based the code on:-

[A][W] = [CA]

=> [W] = [Inverse[A]][CA]

where [A] is a 33x33 matrix containing real coefficients, [W] is a 33x1 matrix of real unknowns and [CA] is a 33x1 matrix of the real RHS of the equations.

Here's the code I used (I imported the matrices from Excel)

-----------------------

ArrayA := Import ("C:\\Documents and Settings\\Administrator\\Desktop\\CA.xls", "Matrix A", "A1:AG33")

ArrayCA := Import ("C:\\Documents and Settings\\Administrator\\Desktop\\CA.xls", "Matrix CA", "A1:A33")

MatrixA := Matrix(33, 33, ArrayA)

MatrixCA := Matrix(33, 1, ArrayCA)

with LinearAlgebra

MatrixW := Multiply((MatrixInverse(MatrixA)), MatrixCA)

----------------------

Any help greatly appreciated

gkokovidis's picture

LinearAlgebra

Look at the help pages for LinearAlgebra, specifically the LinearSolve command.  At the prompt, type the following and hit the enter key.  Take a look at the examples provided.  If it still does not work, post your worksheet, with the data files included.

 

>?LinearAlgebra[LinearSolve]

 

Regards,
Georgios Kokovidis
Dräger Medical


Axel Vogt's picture

i would check the input first

beside what Georgios Kokovidis said (there are better methods for solving a numerical system than inverting)

i would check the data input, either in some coordinates MatrixA[1,2] or for all by using convert(MatrixA, listlist) to see whether all
are floating point numbers, sounds as if  you may have some non-numerical values (it should only need milli seconds) ...

as a remark only: i would avoid blanks in Excel sheet names (even if it works) and may be you should say which Excel version
(not sure whether it runs with the latest shits [sorry, actually i like Excel])

@gkokovidis That worked

@gkokovidis

That worked instantly. Thank you so much. If you can spare the time is there any chance you could enlighten me as to where I went wrong (was it a Maths or programming issue)? Also is there a way to restrict the possible values of the solution set x in the A.x=B system?

What I am trying to do is figure out how a sports management simulation game I play assigns players' attributes. I've found out from going on the game's forums that there is a value that acts as a control on how attributes are distributed for a given player, and that the attributes are distributed to equate to this control.

So I formulated a basic model for a player as a starting point

CA = (w1*A1) + (w2*A2) + (w3*A3) + ........... + (w32*A33) + (w33*A33)

where

CA = Current Ability (the control, known)
wn = weighting n applied to attribute An for n = (0,1,2,3,..........,32,33) (unknowns)
An = attribute n for n = (0,1,2,3,.........,32,33) (known)

and then took 33 players to create the set of equations.

The reason I ask about restricting the values of the solution set is because the w values in the above equation (which correspond to the x vector in A.x=B) are weightings between 0 and 1.

With this model I am making a number of simplifying assumptions initially, and I would like to be certain that the solutions I get from Maple are accurate so any discrepancies I get when I test the model can be blamed solely on the model itself rather than me making mistakes in using Maple to generate the solution set.

@Axel Vogt

Thank you for the suggestions and tips.

Robert Israel's picture

Constraints

Solving a linear system A x = b with bounds such as 0 <= x[i] <= 1 puts you into the domain of Linear Programming.  The LPSolve command in the Optimization package will do this.  If you just want any solution, you can use an objective of 0; with other objectives, you can explore the solution set.

gkokovidis's picture

Method

It was your choice of method.  LinearSolve is optimized for solving a set of linear equations.  I will let others who are more mathematically inclined than myself to comment on restricting the solution set.  Given x equations with x unknowns, there should be only one set of solutions to the given system, assuming a solution set exists.  You can take your vector of unknows and modifiy it in a loop to alter the contents of the vector by a certain amount, and repeatedly solve the system over and over to see what the outcomes look like. 

 

Regards,
Georgios Kokovidis
Dräger Medical


@gkokovidis Thanks again for

@gkokovidis

Thanks again for the swift response. I did remember that when the number of equations equals the number of unknowns there was a unique solution, but when I used LinearSolve I got some unexpected results so I wasn't sure if the hazyness of my memory was affecting my recollection. Time to dust off the old college notes stored in the attic and clear the cobwebs from my brain I think :-)

It's probably the assumptions in my admittedly simplistic model that's producing the unexpected results.

Thanks again for the help.  

acer's picture

not right

It's not true that, "when the number of equations equals the number of unknowns there was a unique solution."

There are three possibilities, when there are n linear equations in n unknowns.

The first possibility is that there are no solutions. The system of equations is usually called inconsistent in this situation. An example could be something like this,

x + y = 2;
2*x + 2*y = 11;

A second possibility is that there are infinitely many solutions. This is often called an underdetermined system. It can arise when one of the equations is a multiple of another (or a linear combination of several other) of the equations. As a result of that, there is not enough data to forcibly pin the variables down to single unique solution values. A simple example is this,

x + y = 2;
2*x + 2*y = 4;

The third possibility is that there is a unique solution.

A discipline of mathematics that formalizes all the above and provides ways to look at and get insight into it is Linear Algebra. Representing the linear multivariate equations as a Matrix, and manipulating that object, can provide nice neat ways to demonstrate which of the three situations above (related to the number of possible solutions) is the case at hand for given data.

acer

@ Robert Israel Thank you

@ Robert Israel

Thank you for the Optimization suggestion but unfortunately I cannot seem to get it to work. If you can spare the time any input on my code (and obvious lack of understanding of how the LPSolve[Optimization] command works) would be greatly appreciated. Here it is:-

--------------------------------------------

with(ExcelTools):
ArrayA := Import("C:\\Documents and Settings\\Administrator\\Desktop\\Misc\\CAx5.xls", "Matrix A", "A1:AF32")
ArrayCA := Import("C:\\Documents and Settings\\Administrator\\Desktop\\Misc\\CAx5.xls", "Matrix CA", "A1:A32")
MatrixA := Matrix(32, 32, ArrayA)
MatrixCA := Matrix(32, 1, ArrayCA)

with(Optimization):
VectorCA := convert(ArrayCA, Vector)
c := 0
Aeq := MatrixA
beq := VectorCA
bl := 0.0001
bu := 1
LPSolve(c, [NoUserValue, NoUserValue, Aeq, beq], [bl, bu])
Error, (in Optimization:-LPSolve) constraints must be specified as a set or list of equalities and inequalities

--------------------------------------------

All of the imported data from Excel has been checked and is accurate.

As it stands the matrices used in Ax=B (in the code above equivalent to MatrixA.x=VectorCA) are based on the model I described previously with the elements of A and B taken from data. But this model is based on underlying assumptions for initial simplification so there might not exist a solution within the constraints 0<x<=1.

Basically I need to know if LPSolve[Optimization] is failing to work because of my misuse or because there is no solution (in which case I can revise my model). Will Maple explicitly tell me if no solution exists?

Robert Israel's picture

LPSolve

I believe your mistake is that in this syntax c should be a Vector.  Try it with

c := Vector(32);

If there is no solution, the error message should be

Error, (in Optimization:-LPSolve) no feasible solution found
 

 

 

acer's picture

then it's a bug?

Isn't that Vector c, when using LPSolve in that "Matrix form" of calling sequence, the coefficient vector of the linear objective function?

If that were so then that reported error message about the contraints would be misleading/mistaken.

acer

Robert Israel's picture

A bug?

Maybe.  I suspect what LPSolve is doing is using the type of the first argument to test whether it's being called in Matrix form or algebraic form.

@ Robert Israel You were

@ Robert Israel

You were right and your correction got the code to run. Thanks again for taking the time to help me. Unfortunately there was no feasible solution so I'll have to go back to the drawing board with my model.

@ acer

You are right and it left me as a beginner scratching my head because from reading the 'Help' section I was pretty certain that my constraints were in the correct form. It was very misleading and I spent many hours trying to figure out why that error was coming up. But because of the error message and my misinterpretation of Robert Israel's original post about setting the objective function to 0 (I made the incorrect assumption that setting c:=0 was interpreted by Maple as meaning there is no objective function) I was banging my head against a brick wall.

It's all part of the learning curve I suppose :-)

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}