Write code and driver MR damper
이전 댓글 표시
@function function ret= MR(t,y)
ret=zeros(4,1);
alva=y(1);
c1=y(2);
co=y(3);
u=y(4);
coa=784; cob=1803;
c1a=14649; c1b=34622;
alvaa=12441; alvab=38430;
eff=190;
ret(1) = alvaa+alvab*u;
ret(2) = c1a+c1b*u;
ret(3) = coa+cob*u;
ret(4) = -eff*(u-v);
end
@driverclear all
clc
tRange = [-750,750];
yZero = [0,0.2,2];
[myT, myY]=ode45(@MR,tRange,yZero);
a = myY(:,1);
b = myY(:,2);
c = myY(:,3);
d = myY(:,4);
figure(1)
plot(myT,myY);
xlabel('time(s)');
ylabel('Force(N)');
z1=a.*d;
z2=b.*d;
z3=c.*d;
And here is the error message I get :
Attempted to access y(4); index out of bounds because numel(y)=3.
Error in MR (line 6)
u=y(4);
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in driveMR (line 7)
[myT, myY]=ode45(@MR,tRange,yZero);
답변 (1개)
Hi @kerollos
The code can run now. However, you have to review the initial values and define for v.
The system looks unstable. Is the instability part of the intended design?
tRange = [-750, 750];
yZero = [0, 0.2, 2, 0]; % <-- there are 4 states, so there must be 4 initial values
[myT, myY] = ode45(@MR, tRange, yZero);
a = myY(:,1);
b = myY(:,2);
c = myY(:,3);
d = myY(:,4);
figure(1)
plot(myT, myY), grid on
xlabel('time(s)');
ylabel('Force(N)');
function ret = MR(t, y)
ret = zeros(4,1);
alva = y(1);
c1 = y(2);
co = y(3);
u = y(4);
coa = 784;
cob = 1803;
c1a = 14649;
c1b = 34622;
alvaa = 12441;
alvab = 38430;
eff = 190;
v = 0; % <-- you need to define for v
ret(1) = alvaa + alvab*u;
ret(2) = c1a + c1b*u;
ret(3) = coa + cob*u;
ret(4) = - eff*(u - v);
end
카테고리
도움말 센터 및 File Exchange에서 Simulation, Tuning, and Visualization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
