error in using eig built-in function

1 回表示 (過去 30 日間)
Alireza
Alireza 2023 年 11 月 14 日
移動済み: John D'Errico 2023 年 11 月 15 日
Hi all,
I run into an issue whrn using the 'eig'.
I have 2 matrcies, and need to find the eigenvalues of using eig function.
Any hints why I run into such an issue?
Thanks in advance.
code snippet including the k and m matrcies are attached.
clc; close all; clear all;
ro = 2700; %kg/m^3
a = 4e-2; %
b = 1e-2;
c = 1; % same as L
L = c;
A = a* b; % cross section area
E = 70e09; % Youngs' modulus
I = (1/12)*(a*b^3)% second moment of area. NOT mass moment
I = 3.3333e-09
% case study is; simply-supported (pined-pined) beam
% lateral or transverse vibrations
syms x
n = 1 : 1 : 10;
gamma = n .* pi ./ L;
% phi = sin(gamma.*x);
for i = 1 : length(n)
for j = 1 : length(n)
phi(i) = sin((i*pi/L)*x);
phi(j) = sin((j*pi/L)*x);
m(i , j) = int(ro*A*phi(i)*phi(j), x, 0, L);
k_RR_Lag(i , j) = int(E*I*(diff(phi(i), x, 2)*diff(phi(j), x, 2)), x, 0, L);
end
end
[eig_vec, eig_val] = eig(k_RR_Lag, m);
Error using sym/eig
Too many input arguments.
% Sort eigenvectors and eigenvalues
[eig_val, idx] = sort(diag(eig_val));
eig_vec = eig_vec(:, idx);
% Display results
disp('Eigenvalues:');
disp(eig_val);
disp('Eigenvectors:');
disp(eig_vec);
  1 件のコメント
Alireza
Alireza 2023 年 11 月 15 日
移動済み: John D'Errico 2023 年 11 月 15 日
Thanksa lot. I got it (the outcome of k and m are not nue=meric values at first, so it is needed to convert them into numeric values (using 'double') then apply the 'eig' function. Or first initialize/preallocate them via zeros ...

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2023 年 11 月 14 日
Symbolic eig() does not support generalized eigenvalues.
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 11 月 14 日
format long g
clc; close all; clear all;
ro = 2700; %kg/m^3
a = 4e-2; %
b = 1e-2;
c = 1; % same as L
L = c;
A = a* b; % cross section area
E = 70e09; % Youngs' modulus
I = (1/12)*(a*b^3)% second moment of area. NOT mass moment
I =
3.33333333333333e-09
% case study is; simply-supported (pined-pined) beam
% lateral or transverse vibrations
syms x
n = 1 : 1 : 10;
gamma = n .* pi ./ L;
% phi = sin(gamma.*x);
for i = 1 : length(n)
for j = 1 : length(n)
phi(i) = sin((i*pi/L)*x);
phi(j) = sin((j*pi/L)*x);
m(i , j) = int(ro*A*phi(i)*phi(j), x, 0, L);
k_RR_Lag(i , j) = int(E*I*(diff(phi(i), x, 2)*diff(phi(j), x, 2)), x, 0, L);
end
end
[eig_vec, eig_val] = eig(double(k_RR_Lag), double(m));
% Sort eigenvectors and eigenvalues
[eig_val, idx] = sort(diag(eig_val));
eig_vec = eig_vec(:, idx);
% Display results
disp('Eigenvalues:');
Eigenvalues:
disp(eig_val);
21045.1739888277 336722.783821243 1704659.09309504 5387564.54113989 13153233.7430173 27274545.4895207 50529462.7471753 86201032.6582382 138077386.540698 210451739.888277
disp('Eigenvectors:');
Eigenvectors:
disp(eig_vec);
Columns 1 through 7 1.36082763487954 0 0 0 0 0 0 0 1.36082763487954 0 0 0 0 0 0 0 1.36082763487954 0 0 0 0 0 0 0 1.36082763487954 0 0 0 0 0 0 0 1.36082763487954 0 0 0 0 0 0 0 1.36082763487954 0 0 0 0 0 0 0 1.36082763487954 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 8 through 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.36082763487954 0 0 0 1.36082763487954 0 0 0 1.36082763487954

サインインしてコメントする。


Dyuman Joshi
Dyuman Joshi 2023 年 11 月 14 日
編集済み: Dyuman Joshi 2023 年 11 月 14 日
The symbolic function eig does not support the syntax that you are trying to use.
The numeric function eig does.
So, you can convert the variables to a numeric data type, preferrably by using double() .
Or you can preallocate them as a double array, as the values will then be automatically stored as double() values -
ro = 2700; %kg/m^3
a = 4e-2; %
b = 1e-2;
c = 1; % same as L
L = c;
A = a* b; % cross section area
E = 70e09; % Youngs' modulus
I = (1/12)*(a*b^3); % second moment of area. NOT mass moment
% case study is; simply-supported (pined-pined) beam
% lateral or transverse vibrations
syms x
n = 1 : 1 : 10;
gamma = n .* pi ./ L;
num = numel(n);
%% Preallocate a double() array
m = zeros(num);
k_RR_Lag = zeros(num);
for i = 1 : length(n)
for j = 1 : length(n)
phii = sin((i*pi/L)*x);
phij = sin((j*pi/L)*x);
m(i , j) = int(ro*A*phii*phij, x, 0, L);
k_RR_Lag(i , j) = int(E*I*(diff(phii, x, 2)*diff(phij, x, 2)), x, 0, L);
end
end
[eig_vec, eig_val] = eig(k_RR_Lag, m);
% Sort eigenvectors and eigenvalues
[eig_val, idx] = sort(diag(eig_val));
eig_vec = eig_vec(:, idx);
% Display results
disp('Eigenvalues:');
Eigenvalues:
disp(eig_val);
1.0e+08 * 0.0002 0.0034 0.0170 0.0539 0.1315 0.2727 0.5053 0.8620 1.3808 2.1045
disp('Eigenvectors:');
Eigenvectors:
disp(eig_vec);
1.3608 0 0 0 0 0 0 0 0 0 0 1.3608 0 0 0 0 0 0 0 0 0 0 1.3608 0 0 0 0 0 0 0 0 0 0 1.3608 0 0 0 0 0 0 0 0 0 0 1.3608 0 0 0 0 0 0 0 0 0 0 1.3608 0 0 0 0 0 0 0 0 0 0 1.3608 0 0 0 0 0 0 0 0 0 0 1.3608 0 0 0 0 0 0 0 0 0 0 1.3608 0 0 0 0 0 0 0 0 0 0 1.3608

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by