# Index exceeds matrix dimensions. Error in UyUzCalc (line 71) u_y2(i+1)=u_y(i)+... Error in Assignment3 (line 150) [u_y2,u_z2​]=UyUzCalc​(x,py2,pz2​,EI1,EI2,B​2)

1 ビュー (過去 30 日間)
Casper Stroem 2017 年 11 月 26 日
コメント済み: Casper Stroem 2017 年 11 月 26 日
i am trying to calculate the deflection of a turbine blade.
%%Assignment 3 - Strukturel
clc
clear all
%Konstanter
%
x=[3.00 6.46 9.46 12.46 15.46 18.46...
21.46 24.46 27.46 28.96 29.86 30.55]; %Definer længder
py=[0 170 170 170 170 170 170 ...
170 170 170 170 170]; %Definer loads
pz=zeros(1,length(py));
B=[0 0 0 0 0 0 0 0 0 0 0 0]; %Definer twist i grader
EI=[1.7e9]
EI1=[1.7e9 5.6657e8 2.3568e8 1.1916e8 5.9832e7 2.9763e7...
1.3795e7 5.3929e6 1.5133e6 6.3600e5 3.5733e5 1.5917e5];
EI2=[1.7e9 1.4003e9 8.5164e8 5.2511e8 3.2937e8 2.0720e8...
1.2099e8 5.9935e7 2.4543e7 1.4047e7 1.0060e7 7.2248e6];%Definer materialekonstant
%
N=length(x);
%Udregn interne krafter på vinge
% T(shear)
% Initier Ty, Tz, My og Mz
Ty=zeros(1,length(x));Tz=zeros(1,length(x));
My=zeros(1,length(x));Mz=zeros(1,length(x));
%--Find Tz og Ty--
for i=N:-1:2
Ty(i-1)=Ty(i)+0.5*(py(i-1)+py(i))*(x(i)-x(i-1));
Tz(i-1)=Tz(i)+0.5*(pz(i-1)+pz(i))*(x(i)-x(i-1));
end
Tz; Ty;
%--Find My og Mz--
for i=N:-1:2
My(i-1)=My(i)-...
Tz(i)*(x(i)-x(i-1))-...
((1/6)*pz(i-1)+(1/3)*pz(i))*(x(i)-x(i-1))^2;
Mz(i-1)=Mz(i)+...
Ty(i)*(x(i)-x(i-1))+...
((1/6)*py(i-1)+(1/3)*py(i))*(x(i)-x(i-1))^2;
end
My; Mz;
%--Brug interne loads til at beregne deflektion--
M1=zeros(1,length(x));M2=zeros(1,length(x)); %Initiate M1 og M2
k1=zeros(1,10); k2=zeros(1,10); %Initiate k1 og k2
theta_y=zeros(1,10); theta_z=zeros(1,10); %Initate theta_y og theta_z
u_y=zeros(1,10); u_z=zeros(1,10); %Inititate u_y og u_z
v=zeros(1,12); %Can assume v=~0
%--Find M1 og M2--
for i=1:N
M1(i)=My(i)*cos(B(i)+v(i))-Mz(i)*sin(B(i)+v(i));
M2(i)=My(i)*sin(B(i)+v(i))+Mz(i)*cos(B(i)+v(i));
end
M1; M2;
%--Find k1 og k2--
for i=1:N
k1(i)=M1(i)/EI;
k2(i)=M2(i)/EI;
end
k1; k2;
%--Find kz og ky--
for i=1:N
kz(i)=-k1(i)*sin(B(i)+v(i))+...
k2(i)*cos(B(i)+v(i));
ky(i)=k1(i)*cos(B(i)+v(i))+...
k2(i)*sin(B(i)+v(i));
end
kz; ky;
%--Find theta_y og theta_z--
for i=1:N-1
theta_y(i+1)=theta_y(i)+...
0.5*(ky(i+1)+ky(i))*(x(i+1)-x(i));
theta_z(i+1)=theta_z(i)+...
0.5*(kz(i+1)+kz(i))*(x(i+1)-x(i));
end
theta_y; theta_z;
%--Find u_y og u_z--
for i=1:N-1
u_y(i+1)=u_y(i)+...
theta_z(i)*(x(i+1)-x(i))+...
((1/6)*kz(i+1)+(1/3)*kz(i))*(x(i+1)-x(i))^2;
u_z(i+1)=u_z(i)-...
theta_y(i)*(x(i+1)-x(i))-...
((1/6)*ky(i+1)+(1/3)*ky(i))*(x(i+1)-x(i))^2;
end
u_y;
u_z;
x2=[0 3.00 6.46 9.46 12.46 15.46 18.46...
21.46 24.46 27.46 28.96 29.86 30.55]; %Definer længder
R=30.55;
zeta=((R)-(x2))/(R)
Uy_ana1=((py*(R-3)^4)/(24*EI).*(zeta(2:end).^4-4*zeta(2:end)+3));
% Uz_ana1=((pz*R^4)./(24.*EI2).*(zeta(2:end).^4-4.*zeta(2:end)+3));
% for c=2:length(x2)
% Uy_ana(c)=((py(c-1)*R^4)/(24*EI1(c-1))*(zeta(c-1)^4-4*zeta(c-1)+3));
% end
% Uy_ana;%mm
% Uy_anaM=Uy_ana*10^-3;%mm
% for c=2:length(x2)
% Uz_ana(c)=(pz(c-1)*R^4/(24*EI2(c-1))*(zeta(c-1)^4-4*zeta(c-1)+3))
% end
% Uz_ana;%mm
% Uz_anaM=Uz_ana*10^-3;%mm
figure
hold on
grid on
plot (x,u_y)
plot(x,Uy_ana1)
legend('calculated','analytical')
Uy_comp=[u_y;Uy_ana1];
%Exercise 2
%table given:
TBL=[8 0 170 2000;12 0 490 3000;20 15.37 200 1200];
py2=zeros(1,length(x)); py3=zeros(1,length(x)); py4=zeros(1,length(x));
pz2=zeros(1,length(x)); pz3=zeros(1,length(x)); pz4=zeros(1,length(x));
py2(2:length(x))=TBL(1,3); py3(2:length(x))=TBL(2,3); py4(2:length(x))=TBL(3,3);
pz2(2:length(x))=TBL(1,4); pz3(2:length(x))=TBL(2,4); pz4(2:length(x))=TBL(3,4);
B2=zeros(1,length(x));
B2(2:length(x))=TBL(1,2); B3=TBL(2,2); B4=TBL(3,2);
[u_y2,u_z2]=UyUzCalc(x,py2,pz2,EI1,EI2,B2)
function [u_y2,u_z2]=UyUzCalc(x,py2,pz2,EI1,EI2,B2)
N=length(x);
%Udregn interne krafter på vinge
% T(shear)
% Initier Ty, Tz, My og Mz
Ty=zeros(1,length(x));Tz=zeros(1,length(x));
My=zeros(1,length(x));Mz=zeros(1,length(x));
%--Find Tz og Ty--
for i=N:-1:2
Ty(i-1)=Ty(i)+0.5*(py2(i-1)+py2(i))*(x(i)-x(i-1));
Tz(i-1)=Tz(i)+0.5*(pz2(i-1)+pz2(i))*(x(i)-x(i-1));
end
Tz; Ty;
%--Find My og Mz--
for i=N:-1:2
My(i-1)=My(i)-...
Tz(i)*(x(i)-x(i-1))-...
((1/6)*pz2(i-1)+(1/3)*pz2(i))*(x(i)-x(i-1))^2;
Mz(i-1)=Mz(i)+...
Ty(i)*(x(i)-x(i-1))+...
((1/6)*py2(i-1)+(1/3)*py2(i))*(x(i)-x(i-1))^2;
end
My; Mz;
%--B2rug interne loads til at B2eregne deflektion--
M1=zeros(1,length(x));M2=zeros(1,length(x)); %Initiate M1 og M2
k1=zeros(1,10); k2=zeros(1,10); %Initiate k1 og k2
theta_y=zeros(1,10); theta_z=zeros(1,10); %Initate theta_y og theta_z
u_y=zeros(1,10); u_z=zeros(1,10); %Inititate u_y og u_z
v=zeros(1,12); %Can assume v=~0
%--Find M1 og M2--
for i=1:N
M1(i)=My(i)*cos(B2(i)+v(i))-Mz(i)*sin(B2(i)+v(i));
M2(i)=My(i)*sin(B2(i)+v(i))+Mz(i)*cos(B2(i)+v(i));
end
M1; M2;
%--Find k1 og k2--
for i=1:N
k1(i)=M1(i)/EI1(i);
k2(i)=M2(i)/EI2(i);
end
k1; k2;
%--Find kz og ky--
for i=1:N
kz(i)=-k1(i)*sin(B2(i)+v(i))+...
k2(i)*cos(B2(i)+v(i));
ky(i)=k1(i)*cos(B2(i)+v(i))+...
k2(i)*sin(B2(i)+v(i));
end
kz; ky;
%--Find theta_y og theta_z--
for i=1:N-1
theta_y(i+1)=theta_y(i)+...
0.5*(ky(i+1)+ky(i))*(x(i+1)-x(i));
theta_z(i+1)=theta_z(i)+...
0.5*(kz(i+1)+kz(i))*(x(i+1)-x(i));
end
theta_y; theta_z;
%--Find u_y og u_z--
for i=1:N-1
u_y2(i+1)=u_y(i)+...
theta_z(i)*(x(i+1)-x(i))+...
((1/6)*kz(i+1)+(1/3)*kz(i))*(x(i+1)-x(i))^2;
u_z2(i+1)=u_z(i)-...
theta_y(i)*(x(i+1)-x(i))-...
((1/6)*ky(i+1)+(1/3)*ky(i))*(x(i+1)-x(i))^2;
end
u_y2;
u_z2;
end
When running calling the function trying to calculate u_y2 and u_z2 using new loads, i get the following error
Index exceeds matrix dimensions.
Error in UyUzCalc (line 71)
u_y2(i+1)=u_y(i)+...
Error in Assignment3 (line 150)
[u_y2,u_z2]=UyUzCalc(x,py2,pz2,EI1,EI2,B2)
please find line 70 and onwards for my function
%--Find u_y og u_z--
for i=1:N-1
u_y2(i+1)=u_y(i)+...
theta_z(i)*(x(i+1)-x(i))+...
((1/6)*kz(i+1)+(1/3)*kz(i))*(x(i+1)-x(i))^2;
u_z2(i+1)=u_z(i)-...
theta_y(i)*(x(i+1)-x(i))-...
((1/6)*ky(i+1)+(1/3)*ky(i))*(x(i+1)-x(i))^2;
end
u_y2;
u_z2;
end

サインインしてコメントする。

### 採用された回答

Walter Roberson 2017 年 11 月 26 日
u_y=zeros(1,10)
so u_y is only 10 elements long.
for i=1:N-1
u_y2(i+1)=u_y(i)+...
theta_z(i)*(x(i+1)-x(i))+...
((1/6)*kz(i+1)+(1/3)*kz(i))*(x(i+1)-x(i))^2;
where N = 12. When i becomes 11, this would attempt to access u_y(11) which does not exist.
In the earlier exercise where you have similar code around line 92, you have
for i=1:N-1
u_y(i+1)=u_y(i)+...
theta_z(i)*(x(i+1)-x(i))+...
((1/6)*kz(i+1)+(1/3)*kz(i))*(x(i+1)-x(i))^2;
which is okay because it extends u_y as it goes.
##### 1 件のコメント表示非表示 なし
Casper Stroem 2017 年 11 月 26 日
thank you so much it works !

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by