MGSolveNonlinearEqnsContinuouslyC.html

MotionGenesis input/output:


   (1) % MotionGenesis file: MGSolveNonlinearEqnsContinuouslyC.txt
   (2) % Copyright (c) 2024 Motion Genesis LLC. All rights reserved.
   (3) % Purpose: Continuous solution to the nonlinear algebraic equations:
   (4) %          x = r*cos(theta)  where x = cos(1.2*t)
   (5) %          y = r*sin(theta)  where y = sin(t)
   (6) % Related: MGSolveNonlinearEqnContinuouslyA.txt
   (7) %          MGSolveNonlinearEqnsContinuouslyB.txt
   (8) %          MGSolveNonlinearEqnsContinuouslyC.txt
   (9) %          MGFigureEightLinkageInverseKinematics.txt
   (10) %-------------------------------------------------------------------------------
   (11) Specified x', y'
   (12) SetDt( x = cos(1.2*t) )
-> (13) x = cos(1.2*t)
-> (14) x' = -1.2*sin(1.2*t)

   (15) SetDt( y = sin(t) )
-> (16) y = sin(t)
-> (17) y' = cos(t)

   (18) %-------------------------------------------------------------------------------
   (19) Variable  r', theta'
   (20) eqnToSolve[1] = x - r*cos(theta)
-> (21) eqnToSolve[1] = x - r*cos(theta)

   (22) eqnToSolve[2] = y - r*sin(theta)
-> (23) eqnToSolve[2] = y - r*sin(theta)

   (24) %-------------------------------------------------------------------------------
   (25) %   Differentiate eqnToSolve to form equations that are _linear_ in r', theta'.
   (26) eqnDt = Dt( eqnToSolve )
-> (27) eqnDt = [x' + r*sin(theta)*theta' - cos(theta)*r';  y' - sin(theta)*r' - r*cos(theta)*theta']

   (28) %-------------------------------------------------------------------------------
   (29) %   Solve eqnDt = 0 to form an ODE (ordinary differential equation) for r' and theta'
   (30) Solve( eqnDt = 0,  r', theta' )
-> (31) r' = x'*cos(theta) + y'*sin(theta)
-> (32) theta' = -(x'*sin(theta)-y'*cos(theta))/r

   (33) %-------------------------------------------------------------------------------
   (34) %   Form a set of equations that govern the values of r and theta at t = 0.
   (35) eqnInitial = Evaluate( eqnToSolve, t = 0 )
-> (36) eqnInitial = [1 - r*cos(theta);  -r*sin(theta)]

   (37) %-------------------------------------------------------------------------------
   (38) %   Solve the nonlinear equations at t = 0 to set initial values for qA and qB.
   (39) %   Since the equations are nonlinear, provide a guess for qA and qB
   (40) SolveSetInput( eqnInitial = 0,  r = 2 meters,  theta = 10 degrees )

->   %  INPUT has been assigned as follows:
->   %   r                         1                       meters
->   %   theta                    -1.13430773684097E-19    degrees

   (41) %-------------------------------------------------------------------------------
   (42) %   List output quantities (for subsequent ODE command).
   (43) Output  t seconds, x meters,  y meters, r meters,  theta degrees
   (44) %--------------------------------------------------------------------
   (45) %   Set numerical integration parameters and solve ODEs.
   (46) Input  tFinal = 7 sec,  tStep = 0.02 sec,  absError = 1.0E-07
   (47) ODE()  MGSolveNonlinearEqnsContinuouslyC

   (48) %-------------------------------------------------------------------------------
   (49) %   Optional: Plot results.
   (50) % Plot MGSolveNonlinearEqnsContinuouslyC.1 [2, 3]   % Graph y vs. x.
   (51) % Plot MGSolveNonlinearEqnsContinuouslyC.1 [1, 5]   % Graph theta vs. time.
   (52) %-------------------------------------------------------------------------------
   (53) %   Record input together with responses.
Saved by MotionGenesis 6.6 Professional user Motion Genesis LLC.
Portions (including program responses) are copyright (c) 2009-2026 Motion Genesis LLC.