#include "stdlib.h"
#include "math.h"



double eq1(double x,double theta,double motorpos1,double lunghezzariposomolla)
            {  
               double MapleGenVar1,MapleGenVar2,MapleGenVar3,MapleGenVar4,MapleGenVar5,MapleGenVar6,MapleGenVar7,t0;
               double MapleGenVar8,MapleGenVar9,MapleGenVar10,MapleGenVar11,MapleGenVar12;
               
                   MapleGenVar6 = 0.1821471932091074E2*sqrt((50625000.0-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*lunghezzariposomolla+
                               lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*
                                 lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)-0.2400000001E13*
                                  lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla+0.4000000002E14*
                                    lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla*
                                   lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
                                    -240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla-0.6071573107636912E3*
                                    sqrt((50625000.0-2700000000.0*lunghezzariposomolla+0.126E12*
                                   lunghezzariposomolla*lunghezzariposomolla+lunghezzariposomolla*
                                  lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
                                    -1200.0*lunghezzariposomolla+29.0)-0.2400000001E13*lunghezzariposomolla*
                                    lunghezzariposomolla*lunghezzariposomolla+0.4000000002E14*lunghezzariposomolla*
                                   lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla)/pow(9.0+8000.0*
                                     lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla,2.0))*
                                           lunghezzariposomolla*lunghezzariposomolla;
                     MapleGenVar7 = MapleGenVar6-0.6830519747008193*sqrt((50625000.0
                                      -2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
                                        lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
                                       lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
                                     -0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
                                              +0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
                                         *lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
                                              -240.0*lunghezzariposomolla,2.0));
                   MapleGenVar5 = MapleGenVar7-0.2320000000116E5*lunghezzariposomolla
                                          -0.960000000048E2*atan2(0.1E-7*(480000000.0+2.0*lunghezzariposomolla-60000000.0
                                         *sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*
                                          lunghezzariposomolla+29.0)+4000000001.0*lunghezzariposomolla*sqrt(40000.0*
                                           lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(
                                                9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla
                                       ),-0.4*(400.0*lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
                                        lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
                                         lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla));
                  MapleGenVar6 = MapleGenVar5+0.1500000000075E3*sqrt(40000.0*
                                            lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+
                                          0.160000000008E4*lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*
                                           lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0);
               MapleGenVar7 = MapleGenVar6-0.2720000000136E5*x;
                 MapleGenVar8 = MapleGenVar7-0.480000000024E2*atan2(0.1E-7*(480000000.0+
                                         2.0*lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
                                           lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
                                             lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*sqrt(
40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+
29.0);
      MapleGenVar9 = MapleGenVar8;
      MapleGenVar11 = 0.480000000024E2*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*x
-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*
x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0
*x))*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar12 = 0.320000000016E4*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*
lunghezzariposomolla*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar10 = MapleGenVar11+MapleGenVar12;
      MapleGenVar4 = MapleGenVar9+MapleGenVar10;
      MapleGenVar7 = MapleGenVar4;
      MapleGenVar9 = -0.240000000012E2*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*sqrt(
40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+
29.0)*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar10 = 0.426666666688E6*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*x
-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*
x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0
*x))*lunghezzariposomolla*x;
      MapleGenVar8 = MapleGenVar9+MapleGenVar10;
      MapleGenVar6 = MapleGenVar7+MapleGenVar8;
      MapleGenVar7 = MapleGenVar6-0.320000000016E4*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0)*x;
      MapleGenVar5 = MapleGenVar7-0.320000000016E4*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*lunghezzariposomolla*sqrt(40000.0*x*x-1200.0*x+29.0)+
0.240000000012E2*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0)+200.0*x*
sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0
*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x))*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)*
sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar3 = MapleGenVar5+0.480000000024E6*x*x+0.120000000006E3*sqrt(
40000.0*x*x-1200.0*x+29.0)+0.960000000048E2*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*
x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0
*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x
-240.0*x))-0.160000000008E4*x*sqrt(40000.0*x*x-1200.0*x+29.0)
-0.1599999999413333E4*lunghezzariposomolla*sqrt(40000.0*x*x-1200.0*x+29.0)
-0.640000000032E4*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0)+200.0*x*
sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0
*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x))*
lunghezzariposomolla;
      MapleGenVar6 = MapleGenVar3-0.480000000024E2*atan2(0.1E-7*(480000000.0+
2.0*lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*sqrt(
40000.0*x*x-1200.0*x+29.0);
      MapleGenVar5 = MapleGenVar6+0.480000000024E2*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0)-0.640000000032E4*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*x+0.106666666672E6*x*sqrt(40000.0*x*x-1200.0*x+29.0)*
lunghezzariposomolla;
      MapleGenVar7 = MapleGenVar5;
      MapleGenVar9 = 0.640000000032E4*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*
lunghezzariposomolla;
      MapleGenVar10 = 0.320000000016E4*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*sqrt(
40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+
29.0)*x;
      MapleGenVar8 = MapleGenVar9+MapleGenVar10;
      MapleGenVar6 = MapleGenVar7+MapleGenVar8;
      MapleGenVar7 = MapleGenVar6+0.9107359660455368E1*sqrt((50625000.0
-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla*sqrt(40000.0*x*x-1200.0*
x+29.0);
      MapleGenVar8 = MapleGenVar7-0.3035786553485123E3*sqrt((50625000.0
-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla*lunghezzariposomolla*
sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar9 = MapleGenVar8;
      MapleGenVar11 = -0.426666666688E6*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*
lunghezzariposomolla*x;
      MapleGenVar12 = 0.4553679830894351E2*sqrt((50625000.0-2700000000.0*
lunghezzariposomolla+0.126E12*lunghezzariposomolla*lunghezzariposomolla+
lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)-0.2400000001E13*
lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla+0.4000000002E14*
lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla*
lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*x;
      MapleGenVar10 = MapleGenVar11+MapleGenVar12;
      MapleGenVar4 = MapleGenVar9+MapleGenVar10;
      MapleGenVar5 = MapleGenVar4+0.960000000048E6*lunghezzariposomolla*x
-0.560000000028E4*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0
*lunghezzariposomolla+29.0)*x-0.320000000016E8*x*x*lunghezzariposomolla+
0.240000000012E6*x*x*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0)-0.341525987283743*sqrt((50625000.0
-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar7 = MapleGenVar5+0.640000000032E4*atan2(0.1E-7*(480000000.0+
2.0*lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*x;
      MapleGenVar6 = MapleGenVar7-0.1214314621394049E4*sqrt((50625000.0
-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla*x+0.4047715404869052E5*
sqrt((50625000.0-2700000000.0*lunghezzariposomolla+0.126E12*
lunghezzariposomolla*lunghezzariposomolla+lunghezzariposomolla*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0)-0.2400000001E13*lunghezzariposomolla*
lunghezzariposomolla*lunghezzariposomolla+0.4000000002E14*lunghezzariposomolla*
lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla)/pow(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla,2.0))*
lunghezzariposomolla*lunghezzariposomolla*x;
      MapleGenVar2 = MapleGenVar6-0.106666666672E6*lunghezzariposomolla*sqrt(
40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+
29.0)*x+0.8000000007066667E3*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)*
sqrt(40000.0*x*x-1200.0*x+29.0)-0.80000000004E3*x*sqrt(40000.0*x*x-1200.0*x+
29.0)*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*
lunghezzariposomolla+29.0)+0.5399999999603333E3;
      MapleGenVar3 = 1/(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(
-400.0*lunghezzariposomolla+6.0+3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0));
      MapleGenVar1 = MapleGenVar2*MapleGenVar3;
      MapleGenVar2 = theta-motorpos1;
      t0 = MapleGenVar1+MapleGenVar2;


               return t0;           
            }

double eq2(double x,double theta,double motorpos2,double lunghezzariposomolla)
            {   
               double MapleGenVar1,MapleGenVar2,MapleGenVar3,MapleGenVar4,MapleGenVar5,MapleGenVar6,MapleGenVar7,t0;
               double MapleGenVar8,MapleGenVar9,MapleGenVar10,MapleGenVar11,MapleGenVar12;
                MapleGenVar6 = 0.5399999999603333E3+0.1821471932091074E2*sqrt((50625000.0-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla;
      MapleGenVar5 = MapleGenVar6-0.6071573107636912E3*sqrt((50625000.0
-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla*lunghezzariposomolla
-0.6830519747008193*sqrt((50625000.0-2700000000.0*lunghezzariposomolla+0.126E12
*lunghezzariposomolla*lunghezzariposomolla+lunghezzariposomolla*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0)-0.2400000001E13*lunghezzariposomolla*
lunghezzariposomolla*lunghezzariposomolla+0.4000000002E14*lunghezzariposomolla*
lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla)/pow(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla,2.0))
-0.2320000000116E5*lunghezzariposomolla;
      MapleGenVar6 = MapleGenVar5-0.960000000048E2*atan2(0.1E-7*(480000000.0+
2.0*lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))+
0.1500000000075E3*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0
*lunghezzariposomolla+29.0);
      MapleGenVar7 = MapleGenVar6+0.160000000008E4*lunghezzariposomolla*sqrt(
40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+
29.0);
      MapleGenVar8 = MapleGenVar7-0.2720000000136E5*x;
      MapleGenVar9 = MapleGenVar8;
      MapleGenVar11 = -0.480000000024E2*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*sqrt(
40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+
29.0);
      MapleGenVar12 = 0.480000000024E2*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*x
-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*
x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0
*x))*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar10 = MapleGenVar11+MapleGenVar12;
      MapleGenVar4 = MapleGenVar9+MapleGenVar10;
      MapleGenVar7 = MapleGenVar4;
      MapleGenVar9 = 0.320000000016E4*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*
lunghezzariposomolla*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar10 = -0.240000000012E2*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*sqrt(
40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+
29.0)*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar8 = MapleGenVar9+MapleGenVar10;
      MapleGenVar6 = MapleGenVar7+MapleGenVar8;
      MapleGenVar7 = MapleGenVar6+0.426666666688E6*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*lunghezzariposomolla*x;
      MapleGenVar5 = MapleGenVar7-0.320000000016E4*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0)*x-0.320000000016E4*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*lunghezzariposomolla*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar6 = MapleGenVar5+0.240000000012E2*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0)*sqrt(40000.0*x*x-1200.0*x+29.0)+
0.480000000024E6*x*x;
      MapleGenVar3 = MapleGenVar6+0.120000000006E3*sqrt(40000.0*x*x-1200.0*x+
29.0)+0.960000000048E2*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0)+
200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x),-0.4*(400.0*x
-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x))
-0.160000000008E4*x*sqrt(40000.0*x*x-1200.0*x+29.0)-0.1599999999413333E4*
lunghezzariposomolla*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar6 = MapleGenVar3-0.640000000032E4*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*lunghezzariposomolla;
      MapleGenVar7 = MapleGenVar6-0.480000000024E2*atan2(0.1E-7*(480000000.0+
2.0*lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*sqrt(
40000.0*x*x-1200.0*x+29.0);
      MapleGenVar5 = MapleGenVar7+0.480000000024E2*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0)-0.640000000032E4*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*x;
      MapleGenVar6 = MapleGenVar5+0.106666666672E6*x*sqrt(40000.0*x*x-1200.0*x+
29.0)*lunghezzariposomolla+0.640000000032E4*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*
lunghezzariposomolla;
      MapleGenVar7 = MapleGenVar6+0.320000000016E4*atan2(0.1E-7*(480000000.0+
2.0*lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*sqrt(
40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+
29.0)*x;
      MapleGenVar8 = MapleGenVar7+0.9107359660455368E1*sqrt((50625000.0
-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla*sqrt(40000.0*x*x-1200.0*
x+29.0);
      MapleGenVar9 = MapleGenVar8;
      MapleGenVar11 = -0.3035786553485123E3*sqrt((50625000.0-2700000000.0*
lunghezzariposomolla+0.126E12*lunghezzariposomolla*lunghezzariposomolla+
lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)-0.2400000001E13*
lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla+0.4000000002E14*
lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla*
lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla*lunghezzariposomolla*
sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar12 = -0.426666666688E6*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*
lunghezzariposomolla*x;
      MapleGenVar10 = MapleGenVar11+MapleGenVar12;
      MapleGenVar4 = MapleGenVar9+MapleGenVar10;
      MapleGenVar5 = MapleGenVar4+0.4553679830894351E2*sqrt((50625000.0
-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*x+0.960000000048E6*lunghezzariposomolla*x
-0.560000000028E4*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla-1200.0
*lunghezzariposomolla+29.0)*x-0.320000000016E8*x*x*lunghezzariposomolla+
0.240000000012E6*x*x*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0);
      MapleGenVar7 = MapleGenVar5-0.341525987283743*sqrt((50625000.0
-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar8 = MapleGenVar7;
      MapleGenVar10 = 0.640000000032E4*atan2(0.1E-7*(480000000.0+2.0*
lunghezzariposomolla-60000000.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)+4000000001.0*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*lunghezzariposomolla*
lunghezzariposomolla-240.0*lunghezzariposomolla),-0.4*(400.0*
lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0))/(9.0+8000.0*
lunghezzariposomolla*lunghezzariposomolla-240.0*lunghezzariposomolla))*x;
      MapleGenVar11 = -0.1214314621394049E4*sqrt((50625000.0-2700000000.0*
lunghezzariposomolla+0.126E12*lunghezzariposomolla*lunghezzariposomolla+
lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)-0.2400000001E13*
lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla+0.4000000002E14*
lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla*
lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla*x;
      MapleGenVar9 = MapleGenVar10+MapleGenVar11;
      MapleGenVar6 = MapleGenVar8+MapleGenVar9;
      MapleGenVar2 = MapleGenVar6+0.4047715404869052E5*sqrt((50625000.0
-2700000000.0*lunghezzariposomolla+0.126E12*lunghezzariposomolla*
lunghezzariposomolla+lunghezzariposomolla*lunghezzariposomolla*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)
-0.2400000001E13*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
+0.4000000002E14*lunghezzariposomolla*lunghezzariposomolla*lunghezzariposomolla
*lunghezzariposomolla)/pow(9.0+8000.0*lunghezzariposomolla*lunghezzariposomolla
-240.0*lunghezzariposomolla,2.0))*lunghezzariposomolla*lunghezzariposomolla*x
-0.106666666672E6*lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0)*x+0.8000000007066667E3*
lunghezzariposomolla*sqrt(40000.0*lunghezzariposomolla*lunghezzariposomolla
-1200.0*lunghezzariposomolla+29.0)*sqrt(40000.0*x*x-1200.0*x+29.0)
-0.80000000004E3*x*sqrt(40000.0*x*x-1200.0*x+29.0)*sqrt(40000.0*
lunghezzariposomolla*lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0);
      MapleGenVar3 = 1/(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(400.0
*lunghezzariposomolla-6.0-3.0*sqrt(40000.0*lunghezzariposomolla*
lunghezzariposomolla-1200.0*lunghezzariposomolla+29.0));
      MapleGenVar1 = MapleGenVar2*MapleGenVar3;
      MapleGenVar2 = theta-motorpos2;
      t0 = MapleGenVar1+MapleGenVar2;

                return t0;                        
            }
            
            
            
double eq3(double x,double motorpos1,double motorpos2,double l3angolinulli)
            {
                double MapleGenVar1,MapleGenVar2,MapleGenVar3,MapleGenVar4,MapleGenVar5,MapleGenVar6,MapleGenVar7,t0;
               double MapleGenVar8,MapleGenVar9,MapleGenVar10,MapleGenVar11;
                MapleGenVar6 = 0.2320000000116E5*l3angolinulli+0.2720000000136E5*x;      MapleGenVar7 = MapleGenVar6-0.640000000032E4*atan2(0.1E-7*(480000000.0+
2.0*l3angolinulli-60000000.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)+4000000001.0*l3angolinulli*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli),-0.4*(400.0*l3angolinulli-6.0-3.0*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli))*l3angolinulli;
      MapleGenVar5 = MapleGenVar7-0.1821471932091074E2*sqrt((50625000.0
-2700000000.0*l3angolinulli+0.126E12*l3angolinulli*l3angolinulli+l3angolinulli*
l3angolinulli*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+
29.0)-0.2400000001E13*l3angolinulli*l3angolinulli*l3angolinulli+0.4000000002E14
*l3angolinulli*l3angolinulli*l3angolinulli*l3angolinulli)/pow(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli,2.0))*l3angolinulli+
0.6071573107636912E3*sqrt((50625000.0-2700000000.0*l3angolinulli+0.126E12*
l3angolinulli*l3angolinulli+l3angolinulli*l3angolinulli*sqrt(40000.0*
l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0)-0.2400000001E13*
l3angolinulli*l3angolinulli*l3angolinulli+0.4000000002E14*l3angolinulli*
l3angolinulli*l3angolinulli*l3angolinulli)/pow(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli,2.0))*l3angolinulli*l3angolinulli;
      MapleGenVar6 = MapleGenVar5-0.480000000024E2*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*sqrt(40000.0*x*x-1200.0*x+29.0)-0.480000000024E6*x*x;
      MapleGenVar4 = MapleGenVar6-0.120000000006E3*sqrt(40000.0*x*x-1200.0*x+
29.0)-0.960000000048E2*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0)+
200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x),-0.4*(400.0*x
-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x))+
0.160000000008E4*x*sqrt(40000.0*x*x-1200.0*x+29.0)+0.640000000032E4*atan2(0.2*(
24.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0
))/(9.0+8000.0*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+
29.0))/(9.0+8000.0*x*x-240.0*x))*x;
      MapleGenVar7 = MapleGenVar4;
      MapleGenVar9 = 0.960000000048E2*atan2(0.1E-7*(480000000.0+2.0*
l3angolinulli-60000000.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)+4000000001.0*l3angolinulli*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli),-0.4*(400.0*l3angolinulli-6.0-3.0*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli));
      MapleGenVar10 = 0.480000000024E2*atan2(0.1E-7*(480000000.0+2.0*
l3angolinulli-60000000.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)+4000000001.0*l3angolinulli*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli),-0.4*(400.0*l3angolinulli-6.0-3.0*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli))*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0);
      MapleGenVar8 = MapleGenVar9+MapleGenVar10;
      MapleGenVar6 = MapleGenVar7+MapleGenVar8;
      MapleGenVar5 = MapleGenVar6-0.1500000000075E3*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0)+0.6830519747008193*sqrt((50625000.0
-2700000000.0*l3angolinulli+0.126E12*l3angolinulli*l3angolinulli+l3angolinulli*
l3angolinulli*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+
29.0)-0.2400000001E13*l3angolinulli*l3angolinulli*l3angolinulli+0.4000000002E14
*l3angolinulli*l3angolinulli*l3angolinulli*l3angolinulli)/pow(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli,2.0))-0.160000000008E4*
l3angolinulli*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+
29.0);
      MapleGenVar6 = MapleGenVar5-0.5399999999603333E3+0.80000000004E3*x*sqrt(
40000.0*x*x-1200.0*x+29.0)*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0);
      MapleGenVar7 = MapleGenVar6-0.320000000016E4*atan2(0.1E-7*(480000000.0+
2.0*l3angolinulli-60000000.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)+4000000001.0*l3angolinulli*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli),-0.4*(400.0*l3angolinulli-6.0-3.0*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli))*l3angolinulli*sqrt(40000.0*x*
x-1200.0*x+29.0);
      MapleGenVar8 = MapleGenVar7-0.106666666672E6*x*sqrt(40000.0*x*x-1200.0*x+
29.0)*l3angolinulli;
      MapleGenVar3 = MapleGenVar8+0.240000000012E2*atan2(0.1E-7*(480000000.0+
2.0*l3angolinulli-60000000.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)+4000000001.0*l3angolinulli*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli),-0.4*(400.0*l3angolinulli-6.0-3.0*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli))*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0)*sqrt(40000.0*x*x-1200.0*x+29.0)
-0.426666666688E6*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0)+200.0*x*
sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0
*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*x))*l3angolinulli*x;
      MapleGenVar6 = MapleGenVar3+0.320000000016E4*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*l3angolinulli*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar7 = MapleGenVar6-0.480000000024E2*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0);
      MapleGenVar5 = MapleGenVar7+0.480000000024E2*atan2(0.1E-7*(480000000.0+
2.0*l3angolinulli-60000000.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)+4000000001.0*l3angolinulli*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli),-0.4*(400.0*l3angolinulli-6.0-3.0*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli))*sqrt(40000.0*x*x-1200.0*x+
29.0)-0.9107359660455368E1*sqrt((50625000.0-2700000000.0*l3angolinulli+0.126E12
*l3angolinulli*l3angolinulli+l3angolinulli*l3angolinulli*sqrt(40000.0*
l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0)-0.2400000001E13*
l3angolinulli*l3angolinulli*l3angolinulli+0.4000000002E14*l3angolinulli*
l3angolinulli*l3angolinulli*l3angolinulli)/pow(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli,2.0))*l3angolinulli*sqrt(40000.0*x*x-1200.0*x
+29.0);
      MapleGenVar6 = MapleGenVar5+0.640000000032E4*atan2(0.2*(24.0-3.0*sqrt(
40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0
*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x))*l3angolinulli+0.3035786553485123E3*sqrt((50625000.0
-2700000000.0*l3angolinulli+0.126E12*l3angolinulli*l3angolinulli+l3angolinulli*
l3angolinulli*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+
29.0)-0.2400000001E13*l3angolinulli*l3angolinulli*l3angolinulli+0.4000000002E14
*l3angolinulli*l3angolinulli*l3angolinulli*l3angolinulli)/pow(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli,2.0))*l3angolinulli*
l3angolinulli*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar7 = MapleGenVar6-0.8000000007066667E3*l3angolinulli*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0)*sqrt(40000.0*x*x
-1200.0*x+29.0);
      MapleGenVar4 = MapleGenVar7+0.560000000028E4*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0)*x+0.320000000016E4*atan2(0.2*(24.0-3.0
*sqrt(40000.0*x*x-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+
8000.0*x*x-240.0*x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0
+8000.0*x*x-240.0*x))*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)*x-0.4047715404869052E5*sqrt((50625000.0-2700000000.0*
l3angolinulli+0.126E12*l3angolinulli*l3angolinulli+l3angolinulli*l3angolinulli*
sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0)
-0.2400000001E13*l3angolinulli*l3angolinulli*l3angolinulli+0.4000000002E14*
l3angolinulli*l3angolinulli*l3angolinulli*l3angolinulli)/pow(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli,2.0))*l3angolinulli*
l3angolinulli*x;
      MapleGenVar5 = MapleGenVar4+0.1214314621394049E4*sqrt((50625000.0
-2700000000.0*l3angolinulli+0.126E12*l3angolinulli*l3angolinulli+l3angolinulli*
l3angolinulli*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+
29.0)-0.2400000001E13*l3angolinulli*l3angolinulli*l3angolinulli+0.4000000002E14
*l3angolinulli*l3angolinulli*l3angolinulli*l3angolinulli)/pow(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli,2.0))*l3angolinulli*x+
0.106666666672E6*l3angolinulli*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)*x-0.4553679830894351E2*sqrt((50625000.0-2700000000.0*
l3angolinulli+0.126E12*l3angolinulli*l3angolinulli+l3angolinulli*l3angolinulli*
sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0)
-0.2400000001E13*l3angolinulli*l3angolinulli*l3angolinulli+0.4000000002E14*
l3angolinulli*l3angolinulli*l3angolinulli*l3angolinulli)/pow(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli,2.0))*x-0.960000000048E6*
l3angolinulli*x+0.1599999999413333E4*l3angolinulli*sqrt(40000.0*x*x-1200.0*x+
29.0);
      MapleGenVar7 = MapleGenVar5+0.426666666688E6*atan2(0.1E-7*(480000000.0+
2.0*l3angolinulli-60000000.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)+4000000001.0*l3angolinulli*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli),-0.4*(400.0*l3angolinulli-6.0-3.0*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli))*l3angolinulli*x;
      MapleGenVar8 = MapleGenVar7;
      MapleGenVar10 = -0.320000000016E4*atan2(0.1E-7*(480000000.0+2.0*
l3angolinulli-60000000.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)+4000000001.0*l3angolinulli*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli),-0.4*(400.0*l3angolinulli-6.0-3.0*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli))*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0)*x;
      MapleGenVar11 = -0.240000000012E2*atan2(0.2*(24.0-3.0*sqrt(40000.0*x*x
-1200.0*x+29.0)+200.0*x*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0*
x),-0.4*(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(9.0+8000.0*x*x-240.0
*x))*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0)*sqrt(
40000.0*x*x-1200.0*x+29.0);
      MapleGenVar9 = MapleGenVar10+MapleGenVar11;
      MapleGenVar6 = MapleGenVar8+MapleGenVar9;
      MapleGenVar7 = MapleGenVar6-0.640000000032E4*atan2(0.1E-7*(480000000.0+
2.0*l3angolinulli-60000000.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0)+4000000001.0*l3angolinulli*sqrt(40000.0*l3angolinulli*
l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli),-0.4*(400.0*l3angolinulli-6.0-3.0*sqrt(
40000.0*l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0))/(9.0+8000.0*
l3angolinulli*l3angolinulli-240.0*l3angolinulli))*x;
      MapleGenVar2 = MapleGenVar7-0.240000000012E6*x*x*sqrt(40000.0*
l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0)+0.320000000016E8*x*x*
l3angolinulli+0.341525987283743*sqrt((50625000.0-2700000000.0*l3angolinulli+
0.126E12*l3angolinulli*l3angolinulli+l3angolinulli*l3angolinulli*sqrt(40000.0*
l3angolinulli*l3angolinulli-1200.0*l3angolinulli+29.0)-0.2400000001E13*
l3angolinulli*l3angolinulli*l3angolinulli+0.4000000002E14*l3angolinulli*
l3angolinulli*l3angolinulli*l3angolinulli)/pow(9.0+8000.0*l3angolinulli*
l3angolinulli-240.0*l3angolinulli,2.0))*sqrt(40000.0*x*x-1200.0*x+29.0);
      MapleGenVar3 = 1/(400.0*x-6.0-3.0*sqrt(40000.0*x*x-1200.0*x+29.0))/(400.0
*l3angolinulli-6.0-3.0*sqrt(40000.0*l3angolinulli*l3angolinulli-1200.0*
l3angolinulli+29.0));
      MapleGenVar1 = MapleGenVar2*MapleGenVar3;
      MapleGenVar2 = motorpos1-motorpos2;
      t0 = MapleGenVar1+MapleGenVar2;


                return t0;                         
            
            }
            
            

double max(double a,double b)
           {if (a>b) return a;
              else return b;
           }
           
           
           
double lunghezzamolla1(double theta,double thetam,double sguess1,double sguess2,double lunghezzariposomolla)
      {
        double tol=1.e-4;
        double fcount=0;
        double toler;
        double a = sguess1; double savea=a;
        double b = sguess2; double saveb=b;
        double fa= eq1(a,theta,thetam,lunghezzariposomolla);
        double fb= eq1(b,theta,thetam,lunghezzariposomolla);
        double fc,c,d,e,s,m,p,q,r;
        fcount=fcount+2;
        if ( fa == 0 )
           return a;
        if ( fb == 0)
           return b;
        fc=fb;
        while (fb != 0)
           {if ((fb > 0) == (fc > 0))
               { c = a;  fc = fa;
                 d = b - a;   e = d;
               }
            if (fabs(fc) < fabs(fb))
                {a = b;    b = c;    c = a;
                 fa = fb;  fb = fc;  fc = fa; 
                }
            m = 0.5*(c - b);
            toler=2.0*tol*max(fabs(b),0.001);
            if ((fabs(m) <= toler) + (fb == 0.0)) 
                break;
            if ((fabs(e) < toler) + (fabs(fa) <= fabs(fb)))
                {d = m;  e = m;
                }
            else
                {s = fb/fa;
                 if (a == c)
                    {p = 2.0*m*s;
                     q = 1.0 - s;
                    }
                 else
                    {q = fa/fc;
                     r = fb/fc;
                     p = s*(2.0*m*q*(q - r) - (b - a)*(r - 1.0));
                     q = (q - 1.0)*(r - 1.0)*(s - 1.0);
                    }
                 if (p > 0) q = -q; else p = -p;
                 if ((2.0*p < 3.0*m*q - fabs(toler*q)) * (p < fabs(0.5*e*q)))
                      {e = d;  d = p/q;
                      }
                 else
                     {d = m;  e = m;
                     }
                     
                 }
            a=b;
            fa=fb;
            if (fabs(d)>toler)
                   b=b+d;
            else 
                {if (b > c) 
                 b = b - toler;
                 else 
                 b = b + toler;
                }
            fb=eq1(b,theta,thetam,lunghezzariposomolla);
            fcount++;
           }
        return b;    
       }
       
       
       
       
double lunghezzamolla2(double theta,double thetam,double sguess1,double sguess2,double lunghezzariposomolla)
      {
        double tol=1.e-4;
        double fcount=0;
        double toler;
        double a = sguess1; double savea=a;
        double b = sguess2; double saveb=b;
        double fa= eq2(a,theta,thetam,lunghezzariposomolla);
        double fb= eq2(b,theta,thetam,lunghezzariposomolla);
        double fc,c,d,e,s,m,p,q,r;
        fcount=fcount+2;
        if ( fa == 0 )
           return a;
        if ( fb == 0)
           return b;
        fc=fb;
        while (fb != 0)
           {if ((fb > 0) == (fc > 0))
               { c = a;  fc = fa;
                 d = b - a;   e = d;
               }
            if (fabs(fc) < fabs(fb))
                {a = b;    b = c;    c = a;
                 fa = fb;  fb = fc;  fc = fa; 
                }
            m = 0.5*(c - b);
            toler=2.0*tol*max(fabs(b),0.001);
            if ((fabs(m) <= toler) + (fb == 0.0)) 
                break;
            if ((fabs(e) < toler) + (fabs(fa) <= fabs(fb)))
                {d = m;  e = m;
                }
            else
                {s = fb/fa;
                 if (a == c)
                    {p = 2.0*m*s;
                     q = 1.0 - s;
                    }
                 else
                    {q = fa/fc;
                     r = fb/fc;
                     p = s*(2.0*m*q*(q - r) - (b - a)*(r - 1.0));
                     q = (q - 1.0)*(r - 1.0)*(s - 1.0);
                    }
                 if (p > 0) q = -q; else p = -p;
                 if ((2.0*p < 3.0*m*q - fabs(toler*q)) * (p < fabs(0.5*e*q)))
                      {e = d;  d = p/q;
                      }
                 else
                     {d = m;  e = m;
                     }
                     
                 }
            a=b;
            fa=fb;
            if (fabs(d)>toler)
                   b=b+d;
            else 
                {if (b > c) 
                 b = b - toler;
                 else 
                 b = b + toler;
                }
            fb=eq2(b,theta,thetam,lunghezzariposomolla);
            fcount++;
           }
        return b;    
       }
       

       
       
       
       
       
       
double lunghezzamolla3(double theta1,double theta2,double sguess1,double sguess2,double lunghezzariposomolla3)
      {
        double tol=1.e-4;
        double fcount=0;
        double toler;
        double a = sguess1; double savea=a;
        double b = sguess2; double saveb=b;
        double fa= eq3(a,theta1,theta2,lunghezzariposomolla3);
        double fb= eq3(b,theta1,theta2,lunghezzariposomolla3);
        double fc,c,d,e,s,m,p,q,r;
        fcount=fcount+2;
        if ( fa == 0 )
           return a;
        if ( fb == 0)
           return b;
        fc=fb;
        while (fb != 0)
           {if ((fb > 0) == (fc > 0))
               { c = a;  fc = fa;
                 d = b - a;   e = d;
               }
            if (fabs(fc) < fabs(fb))
                {a = b;    b = c;    c = a;
                 fa = fb;  fb = fc;  fc = fa; 
                }
            m = 0.5*(c - b);
            toler=2.0*tol*max(fabs(b),0.001);
            if ((fabs(m) <= toler) + (fb == 0.0)) 
                break;
            if ((fabs(e) < toler) + (fabs(fa) <= fabs(fb)))
                {d = m;  e = m;
                }
            else
                {s = fb/fa;
                 if (a == c)
                    {p = 2.0*m*s;
                     q = 1.0 - s;
                    }
                 else
                    {q = fa/fc;
                     r = fb/fc;
                     p = s*(2.0*m*q*(q - r) - (b - a)*(r - 1.0));
                     q = (q - 1.0)*(r - 1.0)*(s - 1.0);
                    }
                 if (p > 0) q = -q; else p = -p;
                 if ((2.0*p < 3.0*m*q - fabs(toler*q)) * (p < fabs(0.5*e*q)))
                      {e = d;  d = p/q;
                      }
                 else
                     {d = m;  e = m;
                     }
                     
                 }
            a=b;
            fa=fb;
            if (fabs(d)>toler)
                   b=b+d;
            else 
                {if (b > c) 
                 b = b - toler;
                 else 
                 b = b + toler;
                }
            fb=eq3(b,theta1,theta2,lunghezzariposomolla3);
            fcount++;
           }
        return b;    
       }
       
       

       
       
       
       
#ifdef __cplusplus
extern "C" { // use the C fcn-call standard for all functions  
#endif       // defined within this scope        
#define S_FUNCTION_NAME  compensatoresemplicissimo
#define S_FUNCTION_LEVEL 2
#include "simstruc.h"      
#define MASS(S) ssGetSFcnParam(S,0)
#define SPRINGCONSTANT(S) ssGetSFcnParam(S,1)
#define SPRINGCONSTANT3(S) ssGetSFcnParam(S,2)
#define INTERNALFRICTION(S) ssGetSFcnParam(S,3)
#define OUTPUTFRICTION(S) ssGetSFcnParam(S,4)       
#define INERTIA(S) ssGetSFcnParam(S,5)         
#define MOTORINERTIA(S) ssGetSFcnParam(S,6)     
#define LUNGHEZZARIPOSOMOLLA(S) ssGetSFcnParam(S,7)
#define LUNGHEZZARIPOSOMOLLA3(S) ssGetSFcnParam(S,8)
#define L3ANGOLINULLI(S) ssGetSFcnParam(S,9)
#define INITIALOUTPUTANGLE(S) ssGetSFcnParam(S,10)
#define INITIALOUTPUTVELOCITY(S) ssGetSFcnParam(S,11)
#define CONTROLCONSTANT(S) ssGetSFcnParam(S,12)
#define STARTINGTHETA(S) ssGetSFcnParam(S,13)
       
            
        
static void mdlInitializeSizes(SimStruct *S)
{
   
    ssSetNumSFcnParams(S, 14);  
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {        
        return;
    }
    ssSetNumContStates(S, 0);
    if (!ssSetNumInputPorts(S, 2)) return;
    ssSetInputPortWidth(S, 0, 1);
    ssSetInputPortWidth(S, 1, 1);
    ssSetInputPortDirectFeedThrough(S, 0, 1);
    ssSetInputPortDirectFeedThrough(S, 1, 1);
    if (!ssSetNumOutputPorts(S, 2)) return;
    ssSetOutputPortWidth(S, 0, 1);
    ssSetOutputPortWidth(S, 1, 1);
 
    ssSetNumSampleTimes(S, 1);
    ssSetInputPortRequiredContiguous(S, 0, true);
    ssSetInputPortRequiredContiguous(S, 1, true);
   
    

}

static void mdlInitializeSampleTimes(SimStruct *S)
{
    ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
    ssSetOffsetTime(S, 0, 0.0);

}



static void mdlOutputs(SimStruct *S, int_T tid)
{
    
    real_T       *torque1 = (real_T*) ssGetOutputPortSignal(S,0);
    real_T       *torque2 = (real_T*) ssGetOutputPortSignal(S,1);
    
    const real_T *in1 = (const real_T*) ssGetInputPortSignal(S,0);
    const real_T *in2 = (const real_T*) ssGetInputPortSignal(S,1);
    
    
    const real_T *mass = mxGetPr(MASS(S));
    const real_T *springconstant = mxGetPr(SPRINGCONSTANT(S));
    const real_T *springconstant3 = mxGetPr(SPRINGCONSTANT3(S));
    const real_T *internalfriction = mxGetPr(INTERNALFRICTION(S));
    const real_T *outputputfriction = mxGetPr(OUTPUTFRICTION(S));
    const real_T *inertia = mxGetPr(INERTIA(S));
    const real_T *motorinertia = mxGetPr(MOTORINERTIA(S));
    const real_T *lriposomolla = mxGetPr(LUNGHEZZARIPOSOMOLLA(S));
    const real_T *lriposomolla3 = mxGetPr(LUNGHEZZARIPOSOMOLLA3(S));
    const real_T *l3angolinulli = mxGetPr(L3ANGOLINULLI(S));
    const real_T *controlconstant = mxGetPr(CONTROLCONSTANT(S));
    const real_T *startingtheta = mxGetPr(STARTINGTHETA(S));
    
    double theta1=*in1+*startingtheta;
    double theta2=*in2-*startingtheta;
    
    double theta=(theta1+theta2)/2;
    
    double l1=lunghezzamolla1(theta,theta1,-0.007,(*lriposomolla)+0.015,*lriposomolla);
    double l2=lunghezzamolla2(theta,theta2,-0.007,(*lriposomolla)+0.015,*lriposomolla);
    double l3=lunghezzamolla3(theta1,theta2,-0.007,(*lriposomolla3)+0.015,*l3angolinulli);
    if(l1<-0.0048)
        l1=-0.0048;
    if(l2<-0.0048)
        l2=-0.0048;
    if(l3<-0.0048)
        l3=-0.0048;    
    double l1vel,l2vel,l3vel;
    
    double m,k,k3,kmollone,mu,radius,j,jmotor,Kt,Kv,R,eff,red;
    double lunghezzariposomolla,lunghezzariposomolla3;
    double f,h,s;
    double MapleGenVar1,MapleGenVar3,MapleGenVar4,MapleGenVar2;
    double MapleGenVar5,MapleGenVar6,MapleGenVar7,MapleGenVar8;
    
    double forza1,forza2,forza3;
    
    
    lunghezzariposomolla=*lriposomolla;
    lunghezzariposomolla3=*lriposomolla3;
    
    
    
    
    
    
    
    

                     

    
    
    
    
    m=*mass;
    k=(*springconstant)*1000.0;
    k3=(*springconstant3)*1000.0;
    kmollone=k*(l3-0.022)/(l3-lunghezzariposomolla3)+k3;
    mu=*internalfriction;
    radius=0.015;
    j=(*inertia)*0.000001;
    
    red=66.0;
    eff=0.7;
    Kt=0.0202;
    R=8.4;
    Kv=(2.115e-3)*60.0/(2.0*3.14159);
    jmotor=*motorinertia;
    l1vel=0;
    l2vel=0;
    l3vel=0;
    
    
    
                   
           
                 


             
             
                    MapleGenVar2 = k*(lunghezzariposomolla-l1)/4.0;      MapleGenVar5 = -m/320.0;
      MapleGenVar7 = 913213440000.0*sqrt(40000.0*l1*l1-1200.0*l1+29.0)*l1vel*
l1vel*l1-0.4798464E18*l1vel*l1vel*l1*l1*l1*l1+0.6397952E19*l1vel*l1vel*l1*l1*l1
*l1*l1-431585280000000.0*l1vel*l1vel*l1*l1-0.3201024E17*l1vel*l1vel*l1*l1*l1*l1
*sqrt(40000.0*l1*l1-1200.0*l1+29.0)+0.19187712E17*l1vel*l1vel*l1*l1*l1+
5683737600000.0*l1vel*l1vel*l1+0.19206144E16*l1vel*l1vel*l1*l1*l1*sqrt(40000.0*
l1*l1-1200.0*l1+29.0)-6472742400.0*sqrt(40000.0*l1*l1-1200.0*l1+29.0)*l1vel*
l1vel-33474124800.0*l1vel*l1vel-59249664000000.0*sqrt(40000.0*l1*l1-1200.0*l1+
29.0)*l1vel*l1vel*l1*l1;
      MapleGenVar8 = 1/(4199040.0*l1+927168000000000.0*sqrt(40000.0*l1*l1
-1200.0*l1+29.0)*l1*l1*l1*l1*l1-0.169344E17*sqrt(40000.0*l1*l1-1200.0*l1+29.0)*
l1*l1*l1*l1*l1*l1+0.16128E18*sqrt(40000.0*l1*l1-1200.0*l1+29.0)*l1*l1*l1*l1*l1*
l1*l1+194643.0*sqrt(40000.0*l1*l1-1200.0*l1+29.0)-0.2388992E18*l1*l1*l1*l1*l1*
l1-7864776000.0*sqrt(40000.0*l1*l1-1200.0*l1+29.0)*l1*l1-31435200000000.0*l1*l1
*l1*l1*sqrt(40000.0*l1*l1-1200.0*l1+29.0)+28683720.0*sqrt(40000.0*l1*l1-1200.0*
l1+29.0)*l1+651067200000.0*sqrt(40000.0*l1*l1-1200.0*l1+29.0)*l1*l1*l1
-0.31744E20*l1*l1*l1*l1*l1*l1*l1*l1-34613568000.0*l1*l1-246216960000000.0*l1*l1
*l1*l1+4120243200000.0*l1*l1*l1+0.9501696E16*l1*l1*l1*l1*l1+0.380928E19*l1*l1*
l1*l1*l1*l1*l1+3086586.0);
      MapleGenVar6 = MapleGenVar7*MapleGenVar8;
      MapleGenVar4 = MapleGenVar5*MapleGenVar6;
      MapleGenVar5 = -mu*l1vel/4.0;
      MapleGenVar3 = MapleGenVar4+MapleGenVar5;
      MapleGenVar1 = MapleGenVar2+MapleGenVar3;
      MapleGenVar2 = 1/(2.0/3.0-1/(45.0+40000.0*l1*l1-1200.0*l1)*(-1600.0*l1+
24.0+12.0*sqrt(40000.0*l1*l1-1200.0*l1+29.0))/4.0+50.0/3.0*l1/(45.0+40000.0*l1*
l1-1200.0*l1)*(-1600.0*l1+24.0+12.0*sqrt(40000.0*l1*l1-1200.0*l1+29.0)))*sqrt(
4.0*pow(2.0/3.0-1/(45.0+40000.0*l1*l1-1200.0*l1)*(-1600.0*l1+24.0+12.0*sqrt(
40000.0*l1*l1-1200.0*l1+29.0))/4.0+50.0/3.0*l1/(45.0+40000.0*l1*l1-1200.0*l1)*(
-1600.0*l1+24.0+12.0*sqrt(40000.0*l1*l1-1200.0*l1+29.0)),2.0)+1/(pow(45.0+
40000.0*l1*l1-1200.0*l1,2.0))*pow(-1600.0*l1+24.0+12.0*sqrt(40000.0*l1*l1
-1200.0*l1+29.0),2.0));
      f = MapleGenVar1*MapleGenVar2;

      
      
      
 

      
      
      
 

      
      
            MapleGenVar2 = k*(lunghezzariposomolla-l2)/4.0;      MapleGenVar5 = m/320.0;
      MapleGenVar7 = 431585280000000.0*l2vel*l2vel*l2*l2+0.4798464E18*l2vel*
l2vel*l2*l2*l2*l2-0.6397952E19*l2vel*l2vel*l2*l2*l2*l2*l2-0.19187712E17*l2vel*
l2vel*l2*l2*l2-5683737600000.0*l2vel*l2vel*l2-913213440000.0*sqrt(40000.0*l2*l2
-1200.0*l2+29.0)*l2vel*l2vel*l2+0.3201024E17*l2vel*l2vel*l2*l2*l2*l2*sqrt(
40000.0*l2*l2-1200.0*l2+29.0)+59249664000000.0*sqrt(40000.0*l2*l2-1200.0*l2+
29.0)*l2vel*l2vel*l2*l2+33474124800.0*l2vel*l2vel+6472742400.0*sqrt(40000.0*l2*
l2-1200.0*l2+29.0)*l2vel*l2vel-0.19206144E16*l2vel*l2vel*l2*l2*l2*sqrt(40000.0*
l2*l2-1200.0*l2+29.0);
      MapleGenVar8 = 1/(3086586.0+927168000000000.0*sqrt(40000.0*l2*l2-1200.0*
l2+29.0)*l2*l2*l2*l2*l2-0.169344E17*sqrt(40000.0*l2*l2-1200.0*l2+29.0)*l2*l2*l2
*l2*l2*l2+0.16128E18*sqrt(40000.0*l2*l2-1200.0*l2+29.0)*l2*l2*l2*l2*l2*l2*l2+
28683720.0*sqrt(40000.0*l2*l2-1200.0*l2+29.0)*l2-7864776000.0*sqrt(40000.0*l2*
l2-1200.0*l2+29.0)*l2*l2-0.31744E20*l2*l2*l2*l2*l2*l2*l2*l2-0.2388992E18*l2*l2*
l2*l2*l2*l2+0.380928E19*l2*l2*l2*l2*l2*l2*l2+0.9501696E16*l2*l2*l2*l2*l2+
4120243200000.0*l2*l2*l2-34613568000.0*l2*l2+194643.0*sqrt(40000.0*l2*l2-1200.0
*l2+29.0)+4199040.0*l2-246216960000000.0*l2*l2*l2*l2+651067200000.0*sqrt(
40000.0*l2*l2-1200.0*l2+29.0)*l2*l2*l2-31435200000000.0*sqrt(40000.0*l2*l2
-1200.0*l2+29.0)*l2*l2*l2*l2);
      MapleGenVar6 = MapleGenVar7*MapleGenVar8;
      MapleGenVar4 = MapleGenVar5*MapleGenVar6;
      MapleGenVar5 = -mu*l2vel/4.0;
      MapleGenVar3 = MapleGenVar4+MapleGenVar5;
      MapleGenVar1 = MapleGenVar2+MapleGenVar3;
      MapleGenVar2 = 1/(2.0/3.0-1/(45.0+40000.0*l2*l2-1200.0*l2)*(-1600.0*l2+
24.0+12.0*sqrt(40000.0*l2*l2-1200.0*l2+29.0))/4.0+50.0/3.0*l2/(45.0+40000.0*l2*
l2-1200.0*l2)*(-1600.0*l2+24.0+12.0*sqrt(40000.0*l2*l2-1200.0*l2+29.0)))*sqrt(
4.0*pow(2.0/3.0-1/(45.0+40000.0*l2*l2-1200.0*l2)*(-1600.0*l2+24.0+12.0*sqrt(
40000.0*l2*l2-1200.0*l2+29.0))/4.0+50.0/3.0*l2/(45.0+40000.0*l2*l2-1200.0*l2)*(
-1600.0*l2+24.0+12.0*sqrt(40000.0*l2*l2-1200.0*l2+29.0)),2.0)+1/(pow(45.0+
40000.0*l2*l2-1200.0*l2,2.0))*pow(-1600.0*l2+24.0+12.0*sqrt(40000.0*l2*l2
-1200.0*l2+29.0),2.0));
      h = MapleGenVar1*MapleGenVar2;

      
      
      
      
      




      
      
      
      
               MapleGenVar2 = kmollone*(lunghezzariposomolla3-l3)/4.0;      MapleGenVar5 = m/320.0;
      MapleGenVar7 = -0.4798464E18*l3vel*l3vel*l3*l3*l3*l3-33474124800.0*l3vel*
l3vel-0.3201024E17*l3vel*l3vel*l3*l3*l3*l3*sqrt(40000.0*l3*l3-1200.0*l3+29.0)
-431585280000000.0*l3vel*l3vel*l3*l3-59249664000000.0*sqrt(40000.0*l3*l3-1200.0
*l3+29.0)*l3vel*l3vel*l3*l3+913213440000.0*sqrt(40000.0*l3*l3-1200.0*l3+29.0)*
l3vel*l3vel*l3+0.19187712E17*l3vel*l3vel*l3*l3*l3+0.19206144E16*l3vel*l3vel*l3*
l3*l3*sqrt(40000.0*l3*l3-1200.0*l3+29.0)+0.6397952E19*l3vel*l3vel*l3*l3*l3*l3*
l3+5683737600000.0*l3vel*l3vel*l3-6472742400.0*sqrt(40000.0*l3*l3-1200.0*l3+
29.0)*l3vel*l3vel;
      MapleGenVar8 = 1/(-3086586.0-194643.0*sqrt(40000.0*l3*l3-1200.0*l3+29.0)+
0.31744E20*l3*l3*l3*l3*l3*l3*l3*l3+246216960000000.0*l3*l3*l3*l3
-4120243200000.0*l3*l3*l3+34613568000.0*l3*l3-0.380928E19*l3*l3*l3*l3*l3*l3*l3+
0.2388992E18*l3*l3*l3*l3*l3*l3-0.9501696E16*l3*l3*l3*l3*l3-4199040.0*l3+
0.169344E17*sqrt(40000.0*l3*l3-1200.0*l3+29.0)*l3*l3*l3*l3*l3*l3-0.16128E18*
sqrt(40000.0*l3*l3-1200.0*l3+29.0)*l3*l3*l3*l3*l3*l3*l3-927168000000000.0*sqrt(
40000.0*l3*l3-1200.0*l3+29.0)*l3*l3*l3*l3*l3+7864776000.0*sqrt(40000.0*l3*l3
-1200.0*l3+29.0)*l3*l3-28683720.0*sqrt(40000.0*l3*l3-1200.0*l3+29.0)*l3+
31435200000000.0*l3*l3*l3*l3*sqrt(40000.0*l3*l3-1200.0*l3+29.0)-651067200000.0*
sqrt(40000.0*l3*l3-1200.0*l3+29.0)*l3*l3*l3);
      MapleGenVar6 = MapleGenVar7*MapleGenVar8;
      MapleGenVar4 = MapleGenVar5*MapleGenVar6;
      MapleGenVar5 = -mu*l3vel/4.0;
      MapleGenVar3 = MapleGenVar4+MapleGenVar5;
      MapleGenVar1 = MapleGenVar2+MapleGenVar3;
      MapleGenVar2 = 1/(2.0/3.0-1/(45.0+40000.0*l3*l3-1200.0*l3)*(-1600.0*l3+
24.0+12.0*sqrt(40000.0*l3*l3-1200.0*l3+29.0))/4.0+50.0/3.0*l3/(45.0+40000.0*l3*
l3-1200.0*l3)*(-1600.0*l3+24.0+12.0*sqrt(40000.0*l3*l3-1200.0*l3+29.0)))*sqrt(
4.0*pow(2.0/3.0-1/(45.0+40000.0*l3*l3-1200.0*l3)*(-1600.0*l3+24.0+12.0*sqrt(
40000.0*l3*l3-1200.0*l3+29.0))/4.0+50.0/3.0*l3/(45.0+40000.0*l3*l3-1200.0*l3)*(
-1600.0*l3+24.0+12.0*sqrt(40000.0*l3*l3-1200.0*l3+29.0)),2.0)+1/(pow(45.0+
40000.0*l3*l3-1200.0*l3,2.0))*pow(-1600.0*l3+24.0+12.0*sqrt(40000.0*l3*l3
-1200.0*l3+29.0),2.0));
      s = MapleGenVar1*MapleGenVar2;


    
      
      
      
      
      

 

 

    forza1=f;
    forza2=h; 
    forza3=s;
    
    *torque1=(*controlconstant)*(radius*forza1-radius*forza3)*R/(Kt*red*eff);
    *torque2=(*controlconstant)*(-radius*forza2+radius*forza3)*R/(Kt*red*eff);
    
    
    
}

    
    
  
static void mdlTerminate(SimStruct *S)
{
}

#ifdef  MATLAB_MEX_FILE    
#include "simulink.c"     
#else
#include "cg_sfun.h"      
#endif
#ifdef __cplusplus
} // end of extern "C" scope
#endif
