Error: Unexpected MATLAB expression
6 views (last 30 days)
Show older comments
Can someone help me with this?
g = 9.81;
m = 0.5;
d = 0.05;
A = 12.e-4;
B = 12.e-4;
C = 4.5e-4;
wspin = (1000*2*pi)/60;
theta = 60;
z = [sind(theta) 0 cosd(theta)];
p = [0 1 0];
y = cross(z,p);
x = cross (y,z);
i = x/norm(x);
j = y/norm(y);
k = z/norm(z);
QXx = [i; j; k];
q0 = dcm2quat(QXx);
w0 = [0 0 wspin]';
t0 = 0;
tf = 2;
f0 = [q0; w0];
[t,f] = rkf45(@rates, [t0,tf], f0);
q = f(:,1:4);
wx = f(:,5);
wy = f(:,6);
wz = f(:,7);
for m = 1:length(t)
QXx = quat2dcm(q(m,:));
[prec(m) nut(m) spin(m)] = dcm2angle(QXx);
end
plotit
`````````````````````````````````````````````````````````
function dfdt = rates(t,f)
q = f(1:4);
wx = f(5);
wy = f(6);
wz = f(7);
q = q/norm(q);
Q = quat2dcm(q);
M = Q*[-m*g*d*Q(3,2)
m*g*d*Q(3,1)
0];
Omega = [ 0 wz -wy wx
-wz 0 wx wy
wy -wx 0 wz
-wx -wy -wz 0];
q_dot = (Omega*q)/2;
wx_dot = (M(1))/A - ((C-B)*wy*wz)/A;
wy_dot = (M(2))/B - ((A-C)*wz*wx)/B;
wz_dot = (M(3))/C - ((B-A)*wx*wy)/C;
dfdt = [q_dot; wx_dot; wy_dot; wz_dot];
end
`````````````````````````````````````````````````````
function plotit
figure(1)
subplot(311)
plot(t, prec)
xlabel('time (s)')
ylabel('precession angle (deg)')
axis([-inf, inf, -inf, inf])
grid
subplot(312)
plot(t, nut)
xlabel('time (s)')
ylabel('nutation angle (deg)')
axis([-inf, inf, -inf, inf])
grid
subplot(313)
plot(t, spin)
xlabel('time (s)')
ylabel('spin angle (deg)')
axis([-inf, inf, -inf, inf])
grid
end
0 Comments
Answers (2)
Walter Roberson
on 14 Oct 2015
.m files cannot include any other period in their name. .m files must follow the rules for MATLAB identifiers: they have to start with a letter (A to Z or a to z), after which you can use letters or digits 0 to 9 or the underscore ('_') character. The maximum length excluding the '.m' is 63 characters.
So you could have named your file Ex23.m or Ex_23.m but not Ex.23.m
0 Comments
Walter Roberson
on 14 Oct 2015
The "`````````````````````````````````````````````````````````" are not valid in MATLAB code.
Otherwise... perhaps you should post the complete error, everything in red
4 Comments
See Also
Categories
Find more on Java Package Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!