Why doesn't it work? - Different size between Left side and Right side

3 views (last 30 days)
% 변수 정의
m = [1100, 200, 70, 17, 7, 1624]; % 질량
k = [25, 400, 6, 330, 290, 25]; % 강성
% 감쇠 계수
alpha = 0.01;
beta = 0.01;
% 초기 조건
x0 = [0; 0; 0; 0; 0; 0]; % 초기 변위 (0으로 설정)
v0 = [10; 10; 10; 10; 10; 10]; % 초기 속도 (10m/s로 설정)
% 감쇠 행렬
C = alpha * diag(m) + beta * diag(k);
% 강제진동 방정식의 특수해 함수
F = @(t) sin(2*pi*10*t); % 예시로 sin(2*pi*10*t) 가진력 사용
% 시간 범위 정의
t = 0:0.001:10; % 0부터 10까지 0.1 단위로 증가하는 시간 벡터
% 모드감쇠 비례감쇠 계수
zeta = [alpha/m(1), alpha/m(2), alpha/m(3), alpha/m(4), alpha/m(5), alpha/m(6)];
% 모드합성법을 위한 모드해 계산
[V, D] = eig(k - 1i*C);
% 각 모드해의 고유진동수와 진동형상 계산
omega = sqrt(diag(D));
phi = V;
% 중첩된 모드해들의 합을 위한 초기화
x_p = zeros(size(phi, 2), length(t));
for i = 1:length(t)
for j = 1:size(phi, 2)
x_p(j, i) = phi(:, j)' * F(t(i)) / ((omega(j)^2) - (2*zeta(j)*omega(j)*1i) - (omega(j)^2));
end
end
% 전체 해 계산 (중첩된 모드해들의 합)
x = real(phi * x_p.' + exp(-zeta(1)*omega(1)*t) * (phi(:, 1)'*x0 + phi(:, 1)'*v0/(omega(1)*sqrt(1 - zeta(1)^2))));
% 결과 그래프 출력
figure;
plot(t, x); % 시간 응답 그래프 출력
xlabel('Time');
ylabel('Displacement');
title('Response of the system');
% At the 37th line, They don't work

Answers (2)

KALYAN ACHARJYA
KALYAN ACHARJYA on 4 Jun 2023
phi(:, j)' * F(t(i)) / ((omega(j)^2) - (2*zeta(j)*omega(j)*1i) - (omega(j)^2));
The result of the above statement is vector, not scalar (single digit), example
>> phi(:, j)' * F(t(i)) / ((omega(j)^2) - (2*zeta(j)*omega(j)*1i) - (omega(j)^2))
ans =
1.0e-10 *
0.0269 - 0.0270i 0.0773 - 0.0774i -0.0894 + 0.0895i 0.7741 - 0.7753i -0.9901 + 0.9901i 0.0163 - 0.0163i
To store vector data, you need to consider the cell array instead of the normal array, please see the description of the cell array here with curly bracket { }
The later step of the code will change, if you consider working with a cell array (specifically *operation).
x_p = cell(size(phi, 2), length(t));
for i = 1:length(t)
for j = 1:size(phi, 2)
disp('kalyan')
x_p{j, i} = phi(:, j)' * F(t(i)) / ((omega(j)^2) - (2*zeta(j)*omega(j)*1i) - (omega(j)^2));
end
Hope it helps!

Atsushi Ueno
Atsushi Ueno on 4 Jun 2023
It's just like below.
a = 0;
a(1,1) = [1 2 3 4 5 6]
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-6.
You should make left-hand variable to ...
  • 3 dimension array
  • cell array
  • other type like struct

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!