Info

This question is closed. Reopen it to edit or answer.

why I get Index exceeds matrix dimensions

1 view (last 30 days)
Latifah Hanum
Latifah Hanum on 1 Mar 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
clear all; close all; clc;
% Parameter
k1=10000; % Kekakuan Lantai 1 (N/m)
k2=10000; % Kekakuan Lantai 2 (N/m)
k3=10000;% Kekakuan Lantai 3 (N/m)
k4=10000;% Kekakuan Lantai 4 (N/m)
k5=10000;% Kekakuan Lantai 5 (N/m)
k6=10000;% Kekakuan Lantai 6 (N/m)
k7=10000;% Kekakuan Lantai 7 (N/m)
c1=500; % Koefisien Redaman Lantai 1(kg/s)
c2=500; % Koefisien Redaman Lantai 2(kg/s)
c3=500;% Koefisien Redaman Lantai 3(kg/s)
c4=500;% Koefisien Redaman Lantai 4(kg/s)
c5=500;% Koefisien Redaman Lantai 5(kg/s)
c6=500;% Koefisien Redaman Lantai 6(kg/s)
c7=500;% Koefisien Redaman Lantai 7(kg/s)
m1=1000; % Massa Lantai 1 (kg)
m2=1000; % Massa Lantai 2 (kg)
m3=1000; % Massa Lantai 3 (kg)
m4=1000; % Massa Lantai 4 (kg)
m5=1000; % Massa Lantai 5 (kg)
m6=1000; % Massa Lantai 6 (kg)
m7=1000; % Massa Lantai 7 (kg)
x10=1; % Nilai awal perpindahan lantai 1 (m)
x20=-1; % Nilai awal perpindahan lantai 1 (m)
x30=2;% Nilai awal perpindahan lantai 1 (m)
x40=-2;% Nilai awal perpindahan lantai 1 (m)
x50=3;% Nilai awal perpindahan lantai 1 (m)
x60=-3;% Nilai awal perpindahan lantai 1 (m)
x70=4;% Nilai awal perpindahan lantai 1 (m)
v10=0; % Nilai kecepatan lantai 1 (m/s)
v20=0; % Nilai kecepatan lantai 1 (m/s)
v30=0;% Nilai kecepatan lantai 1 (m/s)
v40=0;% Nilai kecepatan lantai 1 (m/s)
v50=0;% Nilai kecepatan lantai 1 (m/s)
v60=0;% Nilai kecepatan lantai 1 (m/s)
v70=0;% Nilai kecepatan lantai 1 (m/s)
simwaktu=10; % Waktu simulasi (s)
tStep=0.001;
iterasi=simwaktu/tStep;
t=0:iterasi;
x1=zeros(iterasi,1);
x1(1,:)=x10;
x2=zeros(iterasi,1);
x2(1,:)=x20;
x3=zeros(iterasi,1);
x3(1,:)=x30;
x4=zeros(iterasi,1);
x4(1,:)=x40;
x5=zeros(iterasi,1);
x5(1,:)=x50;
x6=zeros(iterasi,1);
x6(1,:)=x60;
x7=zeros(iterasi,1);
x7(1,:)=x70;
v1=zeros(iterasi,1);
v1(1,:)=v10;
v2=zeros(iterasi,1);
v2(1,:)=v20;
v3=zeros(iterasi,1);
v3(1,:)=v30;
v4=zeros(iterasi,1);
v4(1,:)=v40;
v5=zeros(iterasi,1);
v5(1,:)=v50;
v6=zeros(iterasi,1);
v6(1,:)=v60;
v7=zeros(iterasi,1);
v7(1,:)=v70;
a1=zeros(iterasi,1);
a1(1,:)=-(c1*(v10)-c2*(v20-v10)+k1*(x10)-k2*(x20-x10))/m1;
a2=zeros(iterasi,1);
a2(1,:)=-(c2*(v20-v10)+k2*(x20-x10)-c3*(v30-v20)-k3(x30-x20))/m2;
a3=zeros(iterasi,1);
a3(1,:)=-(c3*(v30-v20)+k3*(x30-x20)-c4*(v40-v30)-k4*(x40-x30))/m3;
a4=zeros(iterasi,1);
a4(1,:)=-(c4*(v40-v30)+k4*(x40-x30)-c5*(v50-v40)-k5*(x50-x40))/m4;
a5=zeros(iterasi,1);
a5(1,:)=-(c5*(v50-v40)+k5*(x50-x40)-c6*(v60-v50)-k6*(x60-x50))/m5;
a6=zeros(iterasi,1);
a6(1,:)=-(c6*(v60-v50)+k6*(x60-x50)-c7*(v70-v60)-k7*(x70-x60))/m6;
a7=zeros(iterasi,1);
a7(1,:)=-(c7*(v70-v60)+k7*(x70-x60))/m7;
% Solve the ODE's with Euler's Method
for n=7:(iterasi+1)
x1(n,:)=x1(n-1,:)+v1(n-1,:)*tStep;
x2(n,:)=x2(n-1,:)+v2(n-1,:)*tStep;
x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;
plot(t',x1,'r')
plot(t',x2,'m')
plot(t',x3,'m')
plot(t',x4,'m')
plot(t',x5,'m')
plot(t',x6,'m')
plot(t',x7,'m')
ylabel('Perpindahan (m)')
title('Pepindahan, Kecepatan, Percepatan Terhadap Waktu')
legend('Lantai 1','Lantai 2','Lantai 3','Lantai 4','Lantai 5','Lantai 6','Lantai 7');
subplot(3,1,2)
hold on;
plot(t',v1,'b')
plot(t',v2,'c')
plot(t',v3,'c')
plot(t',v4,'c')
plot(t',v5,'c')
plot(t',v6,'c')
plot(t',v7,'c')
ylabel('Kecepatan (m/s)');
legend('Lantai 1','Lantai 2','Lantai 3','Lantai 4','Lantai 5','Lantai 6','Lantai 7');
subplot(3,1,3)
hold on;
plot(t',a1,'g')
plot(t',a2,'y')
plot(t',a3,'y')
plot(t',a4,'y')
plot(t',a5,'y')
plot(t',a6,'y')
plot(t',a7,'y')
ylabel('Percepatan (m/s^2)');
xlabel('Waktu (s)');
legend('Lantai 1','Lantai 2','Lantai 3','Lantai 4','Lantai 5','Lantai 6','Lantai 7');

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!