% MotionGenesis file: MGSolveNonlinearEqnsContinuouslyC.txt % Copyright (c) 2024 Motion Genesis LLC. All rights reserved. % Purpose: Continuous solution to the nonlinear algebraic equations: % x = r*cos(theta) where x = cos(1.2*t) % y = r*sin(theta) where y = sin(t) % Related: MGSolveNonlinearEqnContinuouslyA.txt % MGSolveNonlinearEqnsContinuouslyB.txt % MGSolveNonlinearEqnsContinuouslyC.txt % MGFigureEightLinkageInverseKinematics.txt %------------------------------------------------------------------------------- Specified x', y' SetDt( x = cos(1.2*t) ) SetDt( y = sin(t) ) %------------------------------------------------------------------------------- Variable r', theta' eqnToSolve[1] = x - r*cos(theta) eqnToSolve[2] = y - r*sin(theta) %------------------------------------------------------------------------------- % Differentiate eqnToSolve to form equations that are _linear_ in r', theta'. eqnDt = Dt( eqnToSolve ) %------------------------------------------------------------------------------- % Solve eqnDt = 0 to form an ODE (ordinary differential equation) for r' and theta' Solve( eqnDt = 0, r', theta' ) %------------------------------------------------------------------------------- % Form a set of equations that govern the values of r and theta at t = 0. eqnInitial = Evaluate( eqnToSolve, t = 0 ) %------------------------------------------------------------------------------- % Solve the nonlinear equations at t = 0 to set initial values for qA and qB. % Since the equations are nonlinear, provide a guess for qA and qB SolveSetInput( eqnInitial = 0, r = 2 meters, theta = 10 degrees ) %------------------------------------------------------------------------------- % List output quantities (for subsequent ODE command). Output t seconds, x meters, y meters, r meters, theta degrees %-------------------------------------------------------------------- % Set numerical integration parameters and solve ODEs. Input tFinal = 7 sec, tStep = 0.02 sec, absError = 1.0E-07 ODE() MGSolveNonlinearEqnsContinuouslyC %------------------------------------------------------------------------------- % Optional: Plot results. % Plot MGSolveNonlinearEqnsContinuouslyC.1 [2, 3] % Graph y vs. x. % Plot MGSolveNonlinearEqnsContinuouslyC.1 [1, 5] % Graph theta vs. time. %------------------------------------------------------------------------------- % Record input together with responses. Save MGSolveNonlinearEqnsContinuouslyC.html Quit