# Ode45 help in MATLAB

• MATLAB
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))

## Answers and Replies

Related MATLAB, Maple, Mathematica, LaTeX News on Phys.org
Wrichik Basu
Gold Member
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.