David1

65 Reputation

4 Badges

7 years, 295 days

MaplePrimes Activity


These are replies submitted by David1

@MapleMathMatt 

Thanks. I set the environment variable "MATLAB_SYMBOLIC" to maple.

There was no such variable before.

Then I started matlab through the command line.

When I type "maple('1')" this is the error I get:

Same error as before.

Any other idea what I can do to make it work?

Thanks!

@tomleslie 

Thanks for your reply.

Indeed I have Windows 64-bit.

Yes I had Maple 2017 running with Matlab 2017 before I updated to Maple 2018.

I installed Maple 2018 and then deleted Maple 2017.

I did what you said. I clicked on the file "MapleToolbox2018.0WindowsX64Installer.exe" and it created a folder named "maple" in the path "C:\Program Files\MATLAB\R2017a\toolbox\" (Before that I deleted the same folder since it had files related to Maple 2017).

I ran the matlab code and it still didn't run.

This is the error I got:

The file they mention in the error: "C:\Program Files\MATLAB\R2017a\toolbox\maple\maplemex.m" was created when I installed the toolbox with "MapleToolbox2018.0WindowsX64Installer.exe".

Any idea what the problem is?

Thanks.

@acer 

Thanks it worked :).

@acer 

Thanks. it worked on my simple example of f=sin(x).

But when I tried it on a different example it didn't work (I wrote here the simplest example since I assumed that the solution will be the same to my original equations as well).

here's the code I tried (and it still returned a single solution where there are more in the rangle -pi<x<=pi).

I expected the solutions {x=0, x=pi}.


 

restart; eq1 := -1.71010071662834*cos(x)/(25.00000000*cos(x)^2+25.00000000*sin(x)^2)^(1/2); diff_eq1 := expand(diff(eq1, x))

1.71010071662834*sin(x)/(25.00000000*cos(x)^2+25.00000000*sin(x)^2)^(1/2)

(1)

sols := solve({diff_eq1, x > -Pi, x <= Pi}, x, explicit, allsolutions)

{x = 0.}

(2)

``


 

Download trigo.mw

@acer 

I ran the RC option all night and it still didn't show any results. so it seems that if there's any open source that can solve the 18 polynomial equations it most likely uses the Groebner basis (RS option) and not RegularChains.

 

@acer 

Thanks. I saw your older reply and also downloaded the script that you wrote. didn't think about the cached results. It actually makes sense that less digits will take less time (otherwise what's the point of the digits option).

about the method=RC, I'm also trying right now to solve the 18 equations with RC (Maple is still running for over an hour). I'll let it run all night and see if there are any results. I did check RS vs RC for a simpler system of equations (9 equations) and both of them computed the solutions successfuly but RC was much longer (didn't measure the time). Since the RC option uses the RegularChains functions (which are compiled libraries) it seems that I won't be able to run a stand alone code in both RC and RS options. haven't really checked it. first I want to know if Maple is able at all to solve the equations using RC.

Do you happen to know of any other open source that is maybe able to solve the 18 equations? it doesn't seem for now that I'll be able to do it with Maple. or Maple is considered to be the best (and maybe the only?) program for such equations?

@dharr 

Got it.

Thank you for your help!

 

@dharr 

Thanks it worked.

and why did nops(sols) return 4?

Where is the 4 coming from?

@dharr 

It works now. thanks.

The reason it didn't work before is that the link above for Direct Search package is of old version. I downloaded version 2 of this package and then it worked. 

About DirectSearch:-GlobalOptima, I understand that it's not gurantee to return the global minimum (since I tried it on lines+lines. I wrote it bellow as a reply to @acer) and it didn't always return the correct solution. but when it doesn't return the global minimum what does it return? one of the extermum points of the function?

I'm asking because I need to know if the solution is at least close to the correct solution or it can be a completely different solution (for example maximum instead of minimum)?

and one more thing, how can I get the number of solutions in sols in the attached code? when I use nops(sols) I get 4. but it should be 31.

direct_search_example.mw

Thank you for your help!

 

@acer 

Thank you for your code. I tried it in many different functions (different sets of points and lines) and it always found approx 10-20 solutions (which I assume is ALL the possible solutions). it took me on average about 40 minutes to run it each time. I always got reasonable solutions that I assume that are the correct solutions (I can not be 100% sure).

So if I understand correctly, RootFinding:-Isolate is similar to 'solve' but only for polynomial functions? is this function guarantees to return all the possible solutions?

You wrote this in your comments in your code: "Was the goal to find the smallest nonnegative objective value?"

since the expression is sum of squared distances then it can never be negative. so the goal was just to find the global minimum of the function.

is it possible to add restrictions to the variables "r..." (the rotate matrix variables) since we know for sure that each one of them is between -1 to 1 (each vector in the matrix has the norm 1). maybe that way the RootFinding:-Isolate function can run faster?

I'm sorry for asking here since it's beyond the scope of the original question (but that was my original intention). I tried to extend it to lines+lines in 3D (instead of points+lines), but unfortunatelly, in this case the sum of squared distances expression is not polynomial. it's on the form of sum{i=1 to n}(f_i/g_i) where f_i, g_i are polynomials and n is the number of lines in each set. Is there a way in Maple to try to solve this type of equations? I know it's possible to convert this expression into an expression of f/g (where f and g are polynomials) and g=g_1*g_2*...*g_n but in this case f,g polynomials will be of degree O(n) and I assume it will be harder (or impossible) for Maple to solve for n big enough. I tried anyway to do it in Maple but didn't succeed to convert the expression into f/g expression.

I also tried using the rotation with the 3 angles and to try to solve 6 trigonometric equations using DirectSearch:-GlobalSearch (as @dharr showed me above). I indeed got a solution in this case (took me 1:30 hours) but it seems that sometimes the solution is not correct (not the global minima). so maybe is there another way to gurantee the correction of the solution?

I'm attaching an example of the code for lines+lines. The expression 'sum_sqr_distances' is the sum of square distances between 8 rotated and translated lines to 8 corresponding lines in the second set. in this example 'fsolve' doesn't really return the expected solution (the expected solution in this case should be sutiable for sum_sqr_distances=0).

lines_lines_sum_sqr_distances.mw

Is there any command that can return all the possible solutions for this case? or maybe converting the sum of square distances expression into f/g (and for the rest of the differentiate expressions diff_* we take only the numerator which is a polynomial). I just didn't succeed to do the conversion in Maple (and I'm also not sure it's a good idea since the equations will be polynomials of O(n) degree).

Hope there's some way of solving it.

Thank you so much for your help!

 

 

@dharr 

Thanks alot for your code!

It seems that I have alot to learn about Maple instead of wasting my time in matlab.

I tried to follow your code (and also copied DirectSearch from the link above). but I still got an error when running this line:

ans := DirectSearch:-GlobalSearch(Sumsq, [theta = -(1/2)*Pi .. Pi/(2.), phi = 0 .. 2*Pi, psi = 0 .. 2*Pi])

this is the error I get:

Error, (in EvalEq) invalid terms in sum: -1.57079632679490 .. 1.570796327

I'm attaching my code which is based on yours (just changed it to points+points instead of points+lines so I can compare with Kabsch algorithm) so you can see the error.
compare_to_kabsch.mw

a few questions (sorry but I'm on it for so long and it seems that Maple can do alot of things that I planned to do in matlab and save me alot of time):

-How can you tell if DirectSearch:-GlobalSearch actually returned all the minima and didn't miss anything? it doesn't really matter if it takes a long time as long as it's gurantee. what extreme problems are you talking about?

- I'm very interested to know if the optimization can be solved also for lines+lines (in 3D). this was my initial purpose but I started with points+lines. since in lines+lines you still have the same 6 variables, shouldn't Maple be able to solve it?

- in the code I sent (six_trigonometric_equations) the fsolve was much slower than the fsolve of the 18 polynomial equations. how can that be if there are much less variables?

Thanks again!

@dharr 

I did as you suggested (6 trigonometric equations). attaching the file.

even 'fsolve' was very slow this time (for the 18 polynomial equations the 'fsolve' command returned the solutions immediately). the 'fsolve' here returns the correct solution very rarely and is taking much longer.

the 'solve' command of course didn't work at all.

Maybe there are commands in Maple that can deal better with trigonometric equations?

six_trigonometric_equations.mw

@dharr 

But in this case the equations won't be polynomials. they'll be trigonometric equations. aren't they harder to solve?

the other reason I didn't use the 3 angles is that my code is general for any d dimensions (the code is in matlab and I write the commands to maple through matlab). I already found the exact solutions for d=2 (2x2 rotation matrix and 1x2 translation vector). In 2-dimensional I had 9 polynomial equations that Maple was able to solve completely (for d=4, d=5 I also get sometimes the correct solution using 'fsolve' but very rarely).

Using your suggestion the sum of square distances will be a HUGE expression contating many many multiplications of sin, cos of the 3 different angles. (like 4sin(a)cos(b)cos(c)+2cos(b)^2sin(c)+...). I will indeed have only 6 equations instead of 18 but they will be very ugly trigonometric equations that I'm pretty sure will not be solvable. Do you think that Maple will be able to deal with them?

@dharr 

Thanks for your tip. I'm attaching the worksheet after converting all the relevant functions to rational functions. The last command (Groebner:-Solve(..)) still didn't work.

As for @vv's suggestion, I wrote a reply to his comment that I do need all the solutions. I wrote also the mathematical problem that I'm trying to solve. If you think it can be solved without finding all the solutions for the equations I'll be glad to know how. But as far I can see, I need all the solutions.

BTW, if 'f' is the sum of square distances I described bellow, I don't know when I have the minimal f (unless I get a solution in which f=0 but that never really happens). for any solution in which f>0, I cannot know if there's another solution with smaller f. that's why I have to check all the extermum points of the function (all the solutions). 

eighteen_equations.mw

@vv 

This is an optimization problem that I'm trying to solve. I need to find a global minimum of a function. by solving the equations I find all the local extermums (some are maximum points, some are saddle points, some are local minima points). I cannot know which one of the solutions is the solution I need. I have to find all of the extermum points and then check each one of them in order to find the minimum of the function (minimum of all the minimums of the function).

If you're intersted, this is the problem I'm trying to solve:

given a set of n 3D points P={p_1,p_2,...,p_n} and another set of n 3D lines H={h_1,h_2,...,h_n} (each line h_i is represented by a 3D point and a 3D unit vector). I'm trying to find the rotation matrix R=[r11,r12,r12;r21,r22,r23;r31,r32,r33] and a translation vector T=[t1,t2,t3] such that rotating the set P by R and then translating it by T will result in a new set of points PT={pt_1,...,pt_n} such that the sum of square distances between H and PT (sum_{i=1 to n}(dist(h_i,pt_i)^2)) will be minimal. So this is an optimization problem with constraints ( the constraints are R*R^T=I). so there are 12 variables in R and T. Using Lagrange Multipliers algorithm I added 6 more variables (the number of constraints from R*R^T=I) therefore I have overall 18 equations with 18 variables (the equations above) and I need to find the 18 values in which the expression 'h' (in the code above) is minimal. I don't see any way of doint it without getting all the possible solutions and checking each one of them.

 

1 2 3 Page 2 of 3