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 ...
error in using eig built-in function
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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);
Risposte (2)
Walter Roberson
il 14 Nov 2023
Symbolic eig() does not support generalized eigenvalues.
1 Commento
Walter Roberson
il 14 Nov 2023
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
il 14 Nov 2023
Modificato: Dyuman Joshi
il 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);
0 Commenti
Vedere anche
Categorie
Scopri di più su Linear Algebra in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!