필터 지우기
필터 지우기

What is wrong with my code

조회 수: 3 (최근 30일)
Daniel Sode
Daniel Sode 2020년 7월 20일
답변: Dinesh Yadav 2020년 7월 23일
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