What is wrong with my code

N = 16;
E = 200e9; % Young Modulus (Pa)
b = 0.1; % Top width (m^2)
a = 0.025; % Bottom width (m^2)
L = 1.0; % Length (m)
rho = 77e3; % Force density (N/m^3)
Le = L./N;
ff = 0;
for i = 1:N
w(i)=(((i-0.5).*Le)*((b-a)./L))+a; %Calculates avg width (m)
A(i)=w(i).^2; %Calculates element area (m^2)
k(i) = A(i)*E/Le; %Local Stiffness Matrix constact
f(i) = ff*A(i)*le*rho/2; %Local Force Matrix constant
end
KG = zeros(N+1,N+1)
FG = zeros(N+1,N+1)
for ii = 1:N
KG(ii:ii+1,ii:ii+1)=KG(ii:ii+1)+k(i);
FG(ii:ii+1,ii:ii+1)=FG(ii:ii+1)+f(i);
end
Displacement = inv(KG)*FG;
plot(N,Displacement,'b');
hold on
plot(N,Displacement,'*','color','r')
ylabel('end deflection in mm');
xlabel('no of element')

5 comentarios

KSSV
KSSV el 20 de Jul. de 2020
Replace le with Le.
Daniel Sode
Daniel Sode el 20 de Jul. de 2020
Wow thanks I'm getting another error though
Unable to perform assignment because the size of the left side is 2-by-2 and the size of the right side is
1-by-2.
Error in Termproject (line 18)
KG(ii:ii+1,ii:ii+1)=KG(ii:ii+1)+k(i);
KSSV
KSSV el 20 de Jul. de 2020
The first error is solved....
For the second you need to check your logic.....you are trying to save 1X2 array in a 2X2 matrix.
Daniel Sode
Daniel Sode el 20 de Jul. de 2020
I redid the code and am getiing this error
Unable to perform assignment because the left and right sides have a different number of elements.
Error in Termproject (line 10)
w(i)=(((i-0.5).*Le)*((b-a)./L))+a; %Calculates avg width (m)
Daniel Sode
Daniel Sode el 20 de Jul. de 2020
N = linspace(1,16,100);
E = 200e9; % Young Modulus (Pa)
b = 0.1; % Top width (m^2)
a = 0.025; % Bottom width (m^2)
L = 1.0; % Length (m)
rho = 77e3; % Force density (N/m^3)
Le = L./N;
ff = 0;
for i = 1:N
w(i)=(((i-0.5).*Le)*((b-a)./L))+a; %Calculates avg width (m)
A(i)=w(i).^2; %Calculates element area (m^2)
k(i) = (A(i)*E/Le);%*[1 -1;-1 1]; %Local Stiffness Matrix constact
f(i) = (ff*A(i)*Le*rho/2);%*[1;1]; %Local Force Matrix constant
end
KG = zeros(N+1,N+1);
FG = zeros(N+1,N+1);
for i = 1:N
KG(i,i) = KG(i,i) + k(i);
KG(i,i+1) = KG(i,i+1) - k(i);
KG(i+1,i) = KG(i+1,i) - k(i);
KG(i+1,i+1) = KG(i+1,i+1) + k(i);
FG(i,1) = FG(i,1) + f(i);
FG(i+1,1) = FG(i+1,1) +f(i)
end
Displacement = inv(KG)*FG;
plot(N,Displacement,'b');
hold on
plot(N,Displacement,'*','color','r')
ylabel('end deflection in mm');
xlabel('no of element')

Iniciar sesión para comentar.

Respuestas (1)

Dinesh Yadav
Dinesh Yadav el 23 de Jul. de 2020

0 votos

Change to the following code
len = length(N) %N is 1x100 you want i to go from 1 to 100 therefore change to length(N) instean of N
for i = 1:len
w(i)=(((i-0.5)*Le(i))*((b-a)/L))+a; % Le is also 1x100 you want to take one elsment at a time use Le(i)
A(i)=w(i).^2; %
k(i) = (A(i)*E/Le(i));%*[1 -1;-1 1]; %
f(i) = (ff*A(i)*Le(i)*rho/2);%*[1;1]; %
end
KG = zeros(len+1,len+1);
FG = zeros(len+1,len+1);
for i = 1:len

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Versión

R2019a

Etiquetas

Preguntada:

el 20 de Jul. de 2020

Respondida:

el 23 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by