Getting error message when running Runge Kutta solution...

조회 수: 2 (최근 30일)
DJ V
DJ V 2024년 8월 22일
답변: Star Strider 2024년 8월 22일
The code that produces the 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')
The output with the error messages follows:
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0
0.2500
0.5000
0.7500
1.0000
1.2500
1.5000
1.7500
2.0000
2.2500
2.5000
2.7500
3.0000
3.2500
3.5000
3.7500
4.0000
4.2500
4.5000
4.7500
5.0000
5.2500
5.5000
5.7500
6.0000
6.2500
6.5000
6.7500
7.0000
7.2500
7.5000
7.7500
8.0000
8.2500
8.5000
8.7500
9.0000
9.2500
9.5000
9.7500
10.0000
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To
perform elementwise multiplication, use '.*'.
Error in test>@(t,r)(G5*p*r-G6*p*p-G6*r*r+m/Jy) (line 30)
[t,q] = ode45(@(t,r) (G5*p*r - G6*p*p - G6*r*r + m/Jy), [0 10],0);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in test (line 30)
[t,q] = ode45(@(t,r) (G5*p*r - G6*p*p - G6*r*r + m/Jy), [0 10],0);

답변 (1개)

Star Strider
Star Strider 2024년 8월 22일
I’m not certain what you’re modeling. First, using norm to return a scalar solves the first problem of the differential equaton returning a (41x1) vector, however in the expression after that, ‘p’ is (41x1) and ‘q’ is (49x1). You will have to figure out what you want to do with them, and where the error is.
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);
0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000
disp(t);
0 0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000 2.2500 2.5000 2.7500 3.0000 3.2500 3.5000 3.7500 4.0000 4.2500 4.5000 4.7500 5.0000 5.2500 5.5000 5.7500 6.0000 6.2500 6.5000 6.7500 7.0000 7.2500 7.5000 7.7500 8.0000 8.2500 8.5000 8.7500 9.0000 9.2500 9.5000 9.7500 10.0000
[t,q] = ode45(@(t,r) norm(G5.*p.*r - G6.*p.*p - G6.*r.*r + m./Jy), [0 10],0);
plot(t,q,'--g');
G7
G7 = -0.1683
p
p = 41x1
0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
q
q = 49x1
0 0.0001 0.0001 0.0001 0.0002 0.0004 0.0007 0.0009 0.0012 0.0022
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
G7.*p.*q
Arrays have incompatible sizes for this operation.
G1.*q.*r
G4.*l
G8.*n
de(t,r)
[t,r] = ode45(@(t,r) (G7.*p.*q - G1.*q.*r + G4.*l + G8.*n), [0 10],0);
plot(t,r,'--b')
.

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by