What is wrong with my code

1 次查看(过去 30 天)
Daniel Sode
Daniel Sode 2020-7-20
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 个评论
Daniel Sode
Daniel Sode 2020-7-20
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 2020-7-20
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')

请先登录,再进行评论。

回答(1 个)

Dinesh Yadav
Dinesh Yadav 2020-7-23
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

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by