Hello, It's pudding!! I'm new with Matlab and i'm using old version 2011a!!
1 view (last 30 days)
Show older comments
Hello everyone ;
Please I need a help, i wrote a general code for determining natural frequencies and shape modes,but during the execution, i got a problem, no figure!!!
My pleasure if someone help me, please!! here is the code which i wrote it!!
%%%%----------------General Code-------------------%%
clear
clc
close all
n=input('degrees of freedom'); %----le nombre des masses---
M=zeros(n,n);
for i=1:n
M(i,i)=input('input la masse d elemnt');
end
K=zeros(n,n);
disp('0 = pas deconnection');
for i=1:n
K(i,i)=input('element de la raideur connecté à la terre');
end
for i=1:n-1
for j=i+1:n
k=input('connection entre les elements de raideur');
K(i,i)=K(i,i)+k;
K(i,j)=K(i,j)-k;
K(j,i)=K(j,i)-k;
K(j,j)=K(j,j)+k;
end
end
%%----------Calcul de vitesse angulaire naturelle---------%%
[V,D]=eig(K,M);
omega=diag(D).^0.5;
freq_nat=omega/2*pi;
F = cell(numel(n),1);%%-- forces' vectors%%
%%%%%---------Determination of eigenvalues--------%%%
C=zeros(n,n);
disp('0 = pas deconnection');
for i=1:n
C(i,i)=input('element d amortisseur connecté à la terre');
end
for i=1:n-1
for j=i+1:n
k=input('connection entre les elements damortisseur');
C(i,i)=C(i,i)+k;
C(i,j)=C(i,j)-k;
C(j,i)=C(j,i)-k;
C(j,j)=C(j,j)+k;
end
end
%%%%------------Fréquences propres amorties---------%%%
A=[zeros(n,n),M;M,C];
B=[-M,zeros(n,n);zeros(n,n),K];
[V,D]=eig(full(B),full(A));
[omega,tmp]=sort(sqrt(diag(imag(D))),'ascend');
freq_nat=omega/2/pi;
[mode,tmp]=sort((V),'ascend');
%%%for i=1:n
%%V(:,i)=V(:,i)/V(n,i);
%end
for i=1:length(D)
zeta(i)=-(real(D(i)))/(imag(D(i)));
end
for i=1:length(D)
plot(freq_nat(i),zeta(i));
xlabel('frequences naturelles');
ylabel('coefficient damortissement');
end
for i=1:length(V)
plot(V(:,i));
figure()
hold on
title('mode (i)')
hold off
xlabel('overturning moment');
ylabel('');
end
1 Comment
Walter Roberson
on 8 Feb 2025
A=[zeros(n,n),M;M,C];
B=[-M,zeros(n,n);zeros(n,n),K];
None of the values you are putting together here are sparse(), so A and B are not going to be sparse.
[V,D]=eig(full(B),full(A));
There is no point in calling full() on arrays that are not sparse.
Answers (1)
Walter Roberson
on 8 Feb 2025
for i=1:length(D)
plot(freq_nat(i),zeta(i));
You are plotting a scalar against a scalar in each iteration. By default, plot() adds no markers and only joins points if there are at least two adjacent finite points. By plotting a scalar against a scalar, at no time are you asking plot to plot two adjacent finite points... so plot() is plotting nothing.
You have two choices: You can either request a marker, or you can ask to plot() multiple points.
In the case of asking for a marker, you would add a specification such as '*' to your plot() call, making it something like
plot(freq_nat(i), zeta(i), '*');
But... if you are going to plot() a bunch of scalars within a loop, with markers for each, you might as well plot() an entire vector of points at one time outside of any loop, by requesting
plot(freq_nat, zeta, '*')
not in a loop. Unless, that is, you really want each separate point to be a distinct color (and if so then you are better off using scatter())
Plotting multiple points with lines joining the points is just
plot(freq_nat, zeta);
not in a loop.
See Also
Categories
Find more on Data Distribution Plots 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!