Don't understand the reason this code is giving me errors.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
The code that is producing the error is below. It says:
>> test
Error: File: test.m Line: 32 Column: 58
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
>> test
Error: File: test.m Line: 30 Column: 60
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Code that produces errors is below.
clc;
mass = 13.5;
Jx = 0.8244;
Jy = 1.135;
Jz = 1.759;
Jxz = 0.1204;
G = Jx*Jz-Jxz^2;
G1 = Jxz*(Jx - Jy + Jz)/G;
G2 = (Jz*(Jz-Jy)+Jxz^2)/G;
G3 = Jz/G;
G4 = Jxz/G;
G5 = (Jz-Jx)/Jy;
G6 = Jxz/Jy;
G7 = ((Jx-Jy)*Jx +Jxz^2)/G;
G8 = (Jx/G);
p = 0;
q = 0;
r = 0;
l = 0.0000;
m = 0.0000;
n = 0.0000;
tspan = [0 10];
%[t,q] = ode45(@(t,q) (G5*p*r-G6*(p^2-r^2)+m/Jy), tspan,0);
%plot(t,q);
%pdot = (G1*p*q-G2*q*r + G3*l+G4*n);
[t,p]=ode45(@(t,p) (G1*p*q-G2*q*r+G3*l+G4*n),[0 10], 0.1);
plot(t,p,'--r');
disp(p);
disp(t);
[t,q] = ode45(@(t,r) (G5*p*r-G6*p*p-G6*r*r)+m/Jy), [0 10],0);
plot(t,q,'--g');
[t,r] = ode45(@(t,r) (G7*p*q-G1*q*r + G4*l+G8*n), [0 10],0);
plot(t,r,'--b')
0 comentarios
Respuesta aceptada
Voss
el 22 de Ag. de 2024
You have an extra ")" here:
[t,q] = ode45(@(t,r) (G5*p*r-G6*p*p-G6*r*r)+m/Jy), [0 10],0);
% ^ extra parenthesis
That parenthesis closes the ode45 function call, leaving the rest of the line ", [0 10],0);" hanging out with nothing to do, and the closing parenthesis in that part causes the syntax error.
2 comentarios
Voss
el 22 de Ag. de 2024
If the original question is solved, please "Accept" this answer. Thanks!
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!