MATLAB Solve 7 DOF Error in MATLAB with Ode45 - Help from Experts

  • Thread starter Thread starter ksh5022
  • Start date Start date
  • Tags Tags
    Matlab Ode45
AI Thread Summary
The discussion revolves around a programming issue related to calculating 7 degrees of freedom, specifically an error message indicating that "the argument 'x' is undefined." The user provides a function definition for IMatrix, which includes parameters and calculations for Euler parameters and derivatives. The problem arises when attempting to use the variable 'x' in the ode45 function call, where 'x' is not properly defined or initialized. It is suggested that the user may need to replace 'x0' with 'x' in the ode45 function to resolve the error, as 'x0' is initialized but not passed correctly to the function that requires 'x'. This highlights the importance of ensuring that variable names and their scopes are correctly managed in the code to avoid undefined errors.
ksh5022
Messages
1
Reaction score
0
I am writing a program to find 7 degrees of freedom, but I keep getting an error message that "the argument 'x' is undefined". Could somebody please tell me what I am doing wrong?

function dx = IMatrix(t,x,lamda,E)

I1 = 4250;
I2 = 5175;
I3 = 8397;

lamda(1) = 2/(38^.5);
lamda(2) = 5/(38^.5);
lamda(3) = 3/(38^.5);

theta = 15*(pi/180);

E(1) = lamda(1)*sin(theta/2);
E(2) = lamda(2)*sin(theta/2);
E(3) = lamda(3)*sin(theta/2);
E(4) = cos(theta/2);

x0 = [E(1) E(2) E(3) E(4) 0.2 0.7 0.4];

% Derivatives of Euler parameters represented as dx1 - dx4
dx = zeros(7,1);

dx(1) = 0.5*(x(7)*x(2) - x(6)*x(3) + x(5)*x(4));
dx(2) = 0.5*(-x(7)*x(1) + x(5)*x(3) + x(6)*x(4));
dx(3) = 0.5*(x(6)*x(1) - x(5)*x(2) + x(7)*x(4));
dx(4) = 0.5*(-x(5)*x(1) - x(6)*x(2) - x(7)*x(3));

% Derivatives of Euler Equations (w) are replaced with values dx5-dx7

dx(5) = -x(6)*x(7)*(I3-I2)/I1;
dx(6) = -x(7)*x(5)*(I1-I3)/I2;
dx(7) = -x(5)*x(6)*(I2-I1)/I3;

options = odeset('RelTol',1e-8);
[T,X] = ode45(@IMatrix,[0 60],x0,options);

fprintf('---------------------------------------------------')
fprintf('w1 w2 w3 E1 E2 E3 E4 ')
fprintf('---------------------------------------------------')
fprintf(x(1) x(2) x(3) x(4) x(5) x(6) x(7))
 
Physics news on Phys.org
You wrote:
Code:
x0 = [E(1) E(2) E(3) E(4) 0.2 0.7 0.4];
Note that x0 is not the same as x. Maybe that should have been x instead of x0.
 

Similar threads

Back
Top