sirandreus

44 Reputation

2 Badges

17 years, 15 days

MaplePrimes Activity


These are answers submitted by sirandreus

Hi, I´ve implemented acer´s suggestion, because it does not require LinearSolve. so my final procedure looks like this: finalProc := proc (A::(Matrix(datatype = float[8])), v::(Vector(datatype = float[8]))) local n, Ap, vp, C; n := LinearAlgebra:-ColumnDimension(A); Ap := Matrix([[A], [Matrix([[`$`(1, n)]])]], datatype = float[8]); vp := Vector([v, 1.], datatype = float[8]); C := Optimization:-LPSolve(Vector(n), [LinearAlgebra:-NoUserValue, LinearAlgebra:-NoUserValue, Ap, vp], assume = nonnegative)[2]; if hastype(C, negative) then return LinearAlgebra:-Map(max, C, 0) else return C end if end proc hope this is fine. cheers, Andreas
hi Robert, your code solves the issue -> thanks again. Regarding the error situations you mentioned: it would be nice if the procedure returned an empty matrix for this error cases. I think this should not be difficult for the cases, where an error is produced. I guess maple has a try/catch facility, or something comparable. But how could the negative value case be handeled (error issue (2)) without iterating over the result and checking for negative values ? I bet, that there is no workaround, so an iteration should be required. But probably maple´s matrix has somekind of flag where one can efficintly find out whether it contains negative values or not ? I´ve also seen the rounding errors. Of course I could iterate over the result, check for negative values and assign this cases to 0. However, isn´t there a way to prevent maple from doing this kind of errors ? I mean the contraints of the LPSolver clearly say that the values should be positive. If I have to deal with this case manually, is there a non trivial way (I mean without iterating and checking every element) to deal with this case efficiently in maple ? kind regards, Andreas
Hi all, while playing aroung with the solution I encountered a new issue. The A Matrix and the v Vector must be of type float[8]. This is because I´m calling the procedure from Java and the matrix is filled with doubles. my procedure looks like this: solveSystem := proc(A::Matrix(datatype=float[8]), v::Vector(datatype=float[8])) local n, C, ineqs; n := linalg[coldim](A); C := LinearSolve(`<,>`(A, Matrix([[`$`(1., n)]])), `<,>`(v, 1.)); if indets(C) = {} then return C end if; ineqs := map(`>=`, convert(C, set), 0); LPSolve(0, ineqs); return subs(%[2], C) end proc if you call the proc with the following values, then there comes the following error message: Error, (in LinearAlgebra:-LA_Main:-LinearSolve) Matrix requires two indices > A := Matrix([[1, 4], [1, 1]], datatype = float[8]); > v := Vector([[3], [1]], datatype = float[8]); If I remove the float datatype, then everything works fine. However, I need to get it run with float[8]. does anybody see the error ? regards, Andreas
thank you for your kind help
hi, thanks again for the explanation. Last issue: I would like to write a procedure containing your lines of code. If LinearSolve finds a solution (without parameters) I would like to terminate without executing LPSolve. How can I do this ? thank you, Andreas
Hi Robert, thank you for your solution. I tried out several examples and they all seem to work fine. edit: Is it possible that your solution returns negative coefficients if the LinearSolve does not return parameters ? Is there anything to note on the solution, or should it always work without any issues ? kind regards, Andreas
Page 1 of 1