Error: Unexpected MATLAB expression

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

Antworten (2)

Walter Roberson
Walter Roberson am 14 Okt. 2015

2 Stimmen

.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
Walter Roberson am 14 Okt. 2015

0 Stimmen

The "`````````````````````````````````````````````````````````" are not valid in MATLAB code.
Otherwise... perhaps you should post the complete error, everything in red

4 Kommentare

amir azlan
amir azlan am 14 Okt. 2015
thanks for your help with the code,it is my first time using this website. as for the coding, do you know how to fix the error?
Steven Lord
Steven Lord am 14 Okt. 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
amir azlan am 14 Okt. 2015
this is the error massage when i executed the MATLAB code
this is the rkf45 code
if true
% code
end
function [tout, yout] = rkf45(ode_function, tspan, y0, tolerance)
a = [0 1/4 3/8 12/13 1 1/2];
b = [ 0 0 0 0 0
1/4 0 0 0 0
3/32 9/23 0 0 0
1932/2197 -7200/2197 7296/2197 0 0
439/216 -8 3680/513 -854/4104 0
-8/27 2 -3544/2565 1859/4104 -11/40];
c4 = [25/216 0 1408/2565 2197/4104 -1/5 0 ];
c5 = [16/135 0 6656/12825 28561/56430 -9/50 2/55];
if nargin < 4
tol = 1.e-8;
else
tol = tolerance;
end
t0 = tspan(1);
tf = tspan(2);
t = t0;
y = y0;
tout = t;
yout = y';
h = (tf - t0)/100;
while t < tf
hmin = 16*eps(t);
ti = t;
yi = y;
for i = 1:6
t_inner = ti + a(i)*h;
y_inner = yi;
for j = 1:i-1
y_inner = y_inner + h*b(i,j)*f(:,j);
end
f(:,i) = feval(ode_function, t_inner, y_inner);
end
te = h*f*(c4' - c5');
te_max = max(abs(te));
ymax = max(abs(y));
te_allowed = tol*max(ymax,1.0);
delta = (te_allowed/(te_max + eps))^(1/5);
if te_max <= te_allowed
h = min(h, tf-t);
t = t + h;
y = yi + h*f*c5';
tout = [tout;t];
yout = [yout;y'];
end
h = min(delta*h, 4*h);
if h < hmin
fprintf(['\n\n Warning: Step size fell below its minimum\n'
' allowable value (%g) at time %g.\n\n'], hmin, t)
return
end
end

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 14 Okt. 2015

Beantwortet:

am 14 Okt. 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by