error in using eig built-in function
Show older comments
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
% 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);
% 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 Comment
Alireza
on 15 Nov 2023
Moved: John D'Errico
on 15 Nov 2023
Answers (2)
Walter Roberson
on 14 Nov 2023
0 votes
Symbolic eig() does not support generalized eigenvalues.
1 Comment
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
% 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:');
disp(eig_val);
disp('Eigenvectors:');
disp(eig_vec);
Dyuman Joshi
on 14 Nov 2023
Edited: Dyuman Joshi
on 14 Nov 2023
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:');
disp(eig_val);
disp('Eigenvectors:');
disp(eig_vec);
Categories
Find more on Linear Algebra 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!