Don't understand the reason this code is giving me errors.
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Voss
2024 年 8 月 22 日
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 件のコメント
Voss
2024 年 8 月 22 日
If the original question is solved, please "Accept" this answer. Thanks!
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!