Matlab ODE 4.5 Runge Kutta problem solver. Can't get it to work for one problem set.
조회 수: 1 (최근 30일)
이전 댓글 표시
I can't get the problem solver to work for myFun4. I don't understand why. It appears like the prior three myFun1, myFun2, and myFun3. The file is below.
type RG1Combined.m
댓글 수: 0
답변 (1개)
Sam Chak
2024년 9월 13일
Hi @DJ V
You forgot to supply the values for l and n.
theta = 0;
phi = 0;
psi = 0;
Ctheta=cos(theta);
Cphi = cos(phi);
Cpsi = cos(psi);
Stheta = sin(theta);
Sphi = sin(phi);
Spsi = sin(psi);
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;
u = 0;
v = 0;
w = 0;
%m = mass.
m = 11;
%% User-supplied parameters
l = 1;
n = 1;
tRange = [0, 10];
[tSol,uvwAndrSol] = ode45(@(t,uvwAndr)myFun1(t,uvwAndr,Ctheta,Cphi,Cpsi,Stheta,Sphi,Spsi),tRange,[1,1,1]);
length(tSol)
tSol
uvwAndrSol
uvwAndrSol(20,3)
[tSol,xyzAndrSol] = ode45(@(t,xyzAndr)myFun2(t,xyzAndr,p,q,r,u,v,w,m), tRange, [1,1,1]);
length(tSol)
tSol
xyzAndrSol
xyzAndrSol(20,3)
[tSol,pqrAndrSol] = ode45(@(t,pqrAndr)myFun3(t,pqrAndr,p,q,r,phi,psi,theta), tRange, [1,1,1]);
length(tSol)
tSol
pqrAndrSol
pqrAndrSol(20,3)
[tSol,lmnAndrSol] = ode45(@(t,lmnAndr)myFun4(t,lmnAndr,p,q,r,l,m,n,Jx,G1,G2,G3,G4,G5,G6,G7,G8), tRange, [1,1,1]);
length(tSol)
tSol
lmnAndrSol
lmnAndrSol(20,3)
function d_uvwAndr_dt= myFun1(t,uvwAndr,Ctheta,Cphi,Cpsi,Stheta,Sphi,Spsi)
%
d_uvwAndr_dt = zeros(3,1);
d_uvwAndr_dt(1) = Ctheta*Cpsi*Sphi*Stheta*Spsi*uvwAndr(1)-Cphi*Spsi*Cphi*Stheta*Cpsi*uvwAndr(2)+Sphi*Spsi*uvwAndr(3);
d_uvwAndr_dt(2) = Ctheta*Spsi*Stheta*Sphi*Spsi*uvwAndr(1)+Cphi*Cpsi*Cphi*Stheta*Spsi*uvwAndr(2)-Sphi*Cpsi*uvwAndr(3);
d_uvwAndr_dt(3) = -Stheta*uvwAndr(1)+Sphi*Ctheta*uvwAndr(2)+Cphi*Ctheta*uvwAndr(3);
%%
end
function d_xyzAndr_dt=myFun2(t,xyzAndr, p, q, r, u,v,w,m)
%
d_xyzAndr_dt = zeros(3,1);
d_xyzAndr_dt(1) = (r*v-q*w) + (5*t)/m;
d_xyzAndr_dt(2) = (p*w-r*u) + (t)/m;
d_xyzAndr_dt(3) = (q*u-p*v) + (3*t)/m;
%
end
function d_pqrAndr_dt=myFun3(t,pqrAndr,p,q,r,phi,psi,theta)
d_pqrAndr_dt = zeros (3,1);
d_pqrAndr_dt(1) = 1*p + sin(psi)*tan(theta)*q + cos(psi)*tan(theta)*r;
d_pqrAndr_dt(2) = 0*p + cos(phi)*q - sin(phi)*r;
d_pqrAndr_dt(3) = 0*p + sin(phi) / cos(theta) * q +cos(phi) / cos(theta) * r;
end
function d_lmnAndr_dt=myFun4(t,lmnAndr,p,q,r,l,m,n,Jx,G1,G2,G3,G4,G5,G6,G7,G8)
d_lmnAndr_dt = zeros (3,1);
d_lmnAndr_dt(1) = G1*p*q-G2*q*r+G3*l+0/Jx+G4*n;
d_lmnAndr_dt(2) = G5*p*r-G6*(p^2-r^2)+0*l+m/Jx+0*n;
d_lmnAndr_dt(3) = G7*p*q -G1*q*r+G4*l+0/Jx+G8*n;
end
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!