Error: Unexpected MATLAB expression
Mostrar comentarios más antiguos
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
Respuestas (2)
Walter Roberson
el 14 de Oct. de 2015
2 votos
.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
Walter Roberson
el 14 de Oct. de 2015
0 votos
The "`````````````````````````````````````````````````````````" are not valid in MATLAB code.
Otherwise... perhaps you should post the complete error, everything in red
4 comentarios
amir azlan
el 14 de Oct. de 2015
Steven Lord
el 14 de Oct. de 2015
When I copied your code into the Editor, added % before your "separator" lines, and turned your first block of code into a function I saw no red Code Analyzer messages, which I would have expected from the error you paraphrased in your question's subject. I could not execute your code, however, since you didn't provide rkf45.
I would also advise you NOT to try to change the limits of your axes to -Inf to Inf -- you don't have an infinitely wide or tall monitor.
I second Walter's request -- post the FULL, COMPLETE text of the error message that MATLAB displays when you try to execute this code if you need further assistance.
amir azlan
el 14 de Oct. de 2015
amir azlan
el 14 de Oct. de 2015
Categorías
Más información sobre Java Package Integration en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
