1

I'm trying to solve four unknown variables x_Trag, y_Trag, x_Zug, y_Zug with four equations eqx, eqy, Py_Trag, Py_Zug. Sadly only the easy testcase is working.

Here's the Wxmaxima paste:

(%i1)   kill(all); load(ezunits);
Warning: Can set maxima's working directory but cannot change it during the maxima session :

(%o0)   done

(%o1)   "C:/maxima-5.44.0/share/maxima/5.44.0/share/ezunits/ezunits.mac"
  1 easy values work
  1.1 vars
(%i2)   x_GG: 1`mm;
(x_GG)  1 ` mm
(%i3)   y_GG: 18`mm;
(y_GG)  18 ` mm
(%i4)   L_HR: 5`mm;
(L_HR)  5 ` mm
(%i5)   L_Trag: 5`mm;
(L_Trag)    5 ` mm
(%i6)   L_Zug: 15`mm;
(L_Zug) 15 ` mm
(%i7)   x_HR: 4`mm;
(x_HR)  4 ` mm
(%i8)   y_HR: 3`mm;
(y_HR)  3 ` mm
  1.2 equations
(%i9)   eqx: x_Zug=x_GG+x_HR+x_Trag;
(eqx)   x_Zug=x_Trag+5 ` mm
(%i10)  eqy: y_GG=y_HR+y_Zug+y_Trag;
(eqy)   18 ` mm=y_Zug+y_Trag+3 ` mm
(%i11)  Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
(Py_Trag)   25 ` mm^2=y_Trag^2+x_Trag^2
(%i12)  Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;
(Py_Zug)    225 ` mm^2=y_Zug^2+x_Zug^2
  1.3 solving works
(%i13)  res: dimensionally(solve([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, y_Trag, x_Zug, y_Zug]))[1];
(res)   [x_Trag=4 ` mm,y_Trag=3 ` mm,x_Zug=9 ` mm,y_Zug=12 ` mm]
  2 but not the ones I need
  2.1 vars
(%i14)  x_GG: 2`mm;
(x_GG)  2 ` mm
(%i15)  y_GG: 193`mm;
(y_GG)  193 ` mm
(%i16)  L_HR: 46`mm;
(L_HR)  46 ` mm
(%i17)  L_Trag: 50`mm;
(L_Trag)    50 ` mm
(%i18)  L_Zug: 190`mm;
(L_Zug) 190 ` mm
(%i19)  x_HR: 46*cos((149*%pi-360*acos(1/3))/360) ` mm;
(x_HR)  46*cos((149*%pi-360*acos(1/3))/360) ` mm
(%i20)  y_HR: 46*sin((149*%pi-360*acos(1/3))/360) ` mm;
(y_HR)  46*sin((149*%pi-360*acos(1/3))/360) ` mm
  2.2 equations
(%i21)  eqx: x_Zug=x_GG+x_HR+x_Trag;
(eqx)   x_Zug=x_Trag+(46*cos((149*%pi-360*acos(1/3))/360)+2) ` mm
(%i22)  eqy: y_GG=y_HR+y_Zug+y_Trag;
(eqy)   193 ` mm=y_Zug+y_Trag+46*sin((149*%pi-360*acos(1/3))/360) ` mm
(%i23)  Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
(Py_Trag)   2500 ` mm^2=y_Trag^2+x_Trag^2
(%i24)  Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;
(Py_Zug)    36100 ` mm^2=y_Zug^2+x_Zug^2
  2.3 solving takes very long, but dosen't find a solution
(%i26)  res: dimensionally(solve([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, y_Trag, x_Zug, y_Zug])); float(%);
(res)   []
(%o26)  []

wxm-file, which should be better for pasting:

/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/
/* [ Created with wxMaxima version 21.02.0 ] */
/* [wxMaxima: input   start ] */
kill(all); load(ezunits);
/* [wxMaxima: input   end   ] */


/* [wxMaxima: section start ]
easy values work
   [wxMaxima: section end   ] */


/* [wxMaxima: subsect start ]
vars
   [wxMaxima: subsect end   ] */


/* [wxMaxima: input   start ] */
x_GG: 1`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
y_GG: 18`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
L_HR: 5`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
L_Trag: 5`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
L_Zug: 15`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
x_HR: 4`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
y_HR: 3`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: subsect start ]
equations
   [wxMaxima: subsect end   ] */


/* [wxMaxima: input   start ] */
eqx: x_Zug=x_GG+x_HR+x_Trag;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
eqy: y_GG=y_HR+y_Zug+y_Trag;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: subsect start ]
solving works
   [wxMaxima: subsect end   ] */


/* [wxMaxima: input   start ] */
res: dimensionally(solve([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, y_Trag, x_Zug, y_Zug]))[1];
/* [wxMaxima: input   end   ] */


/* [wxMaxima: section start ]
but not the ones I need
   [wxMaxima: section end   ] */


/* [wxMaxima: subsect start ]
vars
   [wxMaxima: subsect end   ] */


/* [wxMaxima: input   start ] */
x_GG: 2`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
y_GG: 193`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
L_HR: 46`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
L_Trag: 50`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
L_Zug: 190`mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
x_HR: 46*cos((149*%pi-360*acos(1/3))/360) ` mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
y_HR: 46*sin((149*%pi-360*acos(1/3))/360) ` mm;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: subsect start ]
equations
   [wxMaxima: subsect end   ] */


/* [wxMaxima: input   start ] */
eqx: x_Zug=x_GG+x_HR+x_Trag;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
eqy: y_GG=y_HR+y_Zug+y_Trag;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: subsect start ]
solving takes very long, but dosen't find a solution
   [wxMaxima: subsect end   ] */


/* [wxMaxima: input   start ] */
res: dimensionally(solve([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, y_Trag, x_Zug, y_Zug])); float(%);
/* [wxMaxima: input   end   ] */



/* Old versions of Maxima abort on loading files that end in a comment. */
"Created with wxMaxima 21.02.0"$
Dux
  • 101
  • 4
  • It looks like the failure to find a solution is a weakness in `solve`. It looks it is having trouble with two things, (1) presence of extra variable corresponding to `mm` which just goes along for the ride, and (2) presence of expressions `cos(...)` and `sin(...)`. Either one of these seems to be enough to make it so that `solve` can't find a solution. I'll try to come up with minimal examples which show that. However, that's not very helpful. I seem to recall someone posted info on the mailing list recently about solving similar equations by giving enough hints. I'll try to find out. – Robert Dodier May 16 '21 at 21:09

1 Answers1

0

I tried some different approaches and some work better than others. What eventually worked was to apply eliminate to reduce the four equations to two, and then apply solve to that. Of course solve should work by itself, and it's a shortcoming that it fails to solve the original set of equations.

Here's my script which you can run via maxima --batch. The solutions which it finds are pretty messy, so I guess you'll have to decide if they're practically useful. One thing to try to make it a little cleaner is to write, say, cos_a and sin_a instead of cos(...) and sin(...). Then you can substitute for cos_a and sin_a after solving.

linel: 65 $
load(ezunits);
x_GG: 2`mm;
y_GG: 193`mm;
L_HR: 46`mm;
L_Trag: 50`mm;
L_Zug: 190`mm;
x_HR: 46*cos((149*%pi-360*acos(1/3))/360) ` mm;
y_HR: 46*sin((149*%pi-360*acos(1/3))/360) ` mm;
eqx: x_Zug=x_GG+x_HR+x_Trag;
eqy: y_GG=y_HR+y_Zug+y_Trag;
Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;

dimensionally (eliminate ([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, x_Zug]));
solutions_y: dimensionally (solve (%, [y_Trag, y_Zug]));
grind (solutions_y);
solutions_y_numerical: float (solutions_y);
solutions_y_numerical_filtered: sublist (%, lambda ([e], every (lambda ([x], qty(x) > 0), map (rhs, e))));

dimensionally (eliminate ([eqx, eqy, Py_Trag, Py_Zug], [y_Trag, y_Zug]));
solutions_x: dimensionally (solve (%, [x_Trag, x_Zug]));
grind (solutions_x);
solutions_x_numerical: float (solutions_x);
solutions_x_numerical_filtered: sublist (%, lambda ([e], every (lambda ([x], qty(x) > 0), map (rhs, e))));

solutions_numerical_filtered: append (solutions_x_numerical_filtered[1], solutions_y_numerical_filtered[1]);
subst (%, [eqx, eqy, Py_Trag, Py_Zug]), numer;

The problem setup is the same as yours, the new stuff is from eliminate onwards. The numerical solution printed towards the end is

[x_Trag = 44.09785089359991 ` mm, 
x_Zug = 91.98740317879643 ` mm, 
y_Trag = 23.56649202927388 ` mm, 
y_Zug = 166.2477598538445 ` mm]

(I was assuming that the solutions with negative quantities are nonphysical -- I guess you can say for sure.)

I also tried to_poly_solve, which is included with Maxima; it wasn't able to solve the original equations.

I am working with Maxima 5.44. I didn't try it on any earlier versions.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48