Error: Array indices must be positive integers or logical values.

조회 수: 17 (최근 30일)
I been using ode45 to solve an coupled equation. I keep getting the error Array indices must be positive integers or logical values for this part of my code " -2*zeta2*(z(4)-z(2))-w2^2*(z(3)-z(1))-2*zeta2(z(4)-z(2))-w2^2*(z(3)-z(1))+(ki*(z(1)-z(3)-d1)+ci*(z(2)-z(4)))/m2-F1*cos(w*t);" I have tried changing the values, changing the variables and I still get the error.
%% Clear Memory
clc;
clear all;
close all
global w F1 F2 F3 F4 d1 d2
%% Excitation Amplitude
g = 9.81;
F1 = 0.05*g;
F2 = 0.1*g;
F3 = 0.5*g;
F4 = 1.0*g;
%%
Omega =[250:3:400];
%% Distance to determine which case
x1 = 2;
x2 = 12;
x = x1-x2;
%% F1
% if x<-d1
i=1; % Initilize the loop counter
for w=Omega
%Tint is the time interval for the time integration
%(start and end).
Tstep=60; % Time step, the maximum Tstep the lower time interval
Per =2*pi/w; % Period of Excitations
Tint=[0:Per/Tstep:500*Per]; % Tint is the time interval
x0v0=[0;0;0;0;0]; % Define IC's
[t,x]=ode45(@LIFun,Tint,x0v0); % Use the ode45 solver to call the Function Q1Fun get time respons
[rT,cT]=size(t); % Use the ode45 solver to get time respons
X=[x(rT-Tstep+1:rT,:)]; % Find the steady state amplitudes for the last 60 periods
XMAX1(i)=max(X(:,2))*1e3; % Find the Max amplitude from the steady state amplitude of the last 60 periods
%VMAX1(i)=max(X(:,4)); % Find the Max amplitude from the steady state amplitude of the last 60 periods
i=i+1; % Update the loop counter
end
%% Left Impact Function F1
function dzdt = LIFun(t,z)
global w F1 d1 d2
m1 = 0.056; %kg
m2 = 0.0084; %kg
k1 = 1500; %N/m
k2 = 144; %N/m
c1 = 0.1833; %Ns/m
c2 = 0.0132; %Ns/m
w1 = sqrt(k1/m1);
w2 = sqrt(k2/m2);
zeta1 = c1/(2*sqrt(k1*m1));
zeta2 = c2/(2*sqrt(k2*m2));
ki = 2000; %N/m
ci = 80; %Ns/m
d1 = 5e-3; %m
d2 = 5e-3; %m
T1 = 10e-6;
T2 = 10e-6;
S = 1;
epsilon = 8.854e-12;
epsilon_r = 1;
sigma = 5;
A = 1;
R = 10e6;
dzdt=[z(2);
-2*zeta1*w1*z(2)-w1^2*z(1)+2*zeta1*w1*(z(4)-z(2))+w1^2*(z(2)-z(1))+2*zeta1*(z(4)-z(2))+w1^2*(z(3)-z(1))+(ki*(z(3)-z(1)-d1)+ci*(z(2)-z(4)))/m1-F1*cos(w*t);
z(4);
-2*zeta2*(z(4)-z(2))-w2^2*(z(3)-z(1))-2*zeta2(z(4)-z(2))-w2^2*(z(3)-z(1))+(ki*(z(1)-z(3)-d1)+ci*(z(2)-z(4)))/m2-F1*cos(w*t);
-z(5)/(S*epsilon*R)*(T1/epsilon_r+d1+(z(1)-z(3)))+(sigma*A*(d1+(z(1)-z(3)))/(epsilon*S*R))];

채택된 답변

Steven Lord
Steven Lord 2021년 4월 21일
-2*zeta2(z(4)-z(2))
Is z(4)-z(2) guaranteed to be a positive integer value suitable for use as an index into the variable zeta2? Or did you mean to multiply zeta2 by the quantity (z(4)-z(2)) and accidentally omitted the multiplication sign?
  댓글 수: 1
Alexandra Craig
Alexandra Craig 2021년 4월 21일
I accidentally omitted the multiplication sign. Thank you for pointing that out, it now runs

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by