Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Errors : undefined function or variable, too many output arguements- do not know why..please help. Struggling.
1 回表示 (過去 30 日間)
古いコメントを表示
I really am struggling with Matlab. Actally, I have a Mathcad code which has to be converted into Matlab.
See this code;
% This the input file.
% We first accept the inputs of: nodal coordinates, element
% connectivity,material properties through an xls file.
% N_C = nodal coordinates.
% E_C = element connectivity.
% A_E= area of cross section per element.
% E_E = modulus of elasticity per element.
% rho_E = density of the material per element.
% N_NBC = number of nodes where Neumann boundary conditions are introduced.
% p = order of approximation.
% n_dof = number of degrees of freedom
p=1;
n_dof=p+1;
N_C=xlsread('C:\Users\Ajay Taneja\vibrations\free_vibrations_program\matlab_input_free_vibrations_1','Sheet1');
E_C=xlsread('C:\Users\Ajay Taneja\vibrations\free_vibrations_program\matlab_input_free_vibrations_1','Sheet2');
xlRange='A1:A2';
A_E=xlsread('C:\Users\Ajay Taneja\vibrations\free_vibrations_program\matlab_input_free_vibrations_1','Sheet3',xlRange);
xlRange='B1:B2';
E_E=xlsread('C:\Users\Ajay Taneja\vibrations\free_vibrations_program\matlab_input_free_vibrations_1','Sheet3',xlRange);
xlRange='C1:C2';
rho_E=xlsread('C:\Users\Ajay Taneja\vibrations\free_vibrations_program\matlab_input_free_vibrations_1','Sheet3',xlRange);
no_of_elements=size(E_C);
E_k=zeros(50,2,2);
E_k_temp=zeros(2,2);
for i=1:no_of_elements
E_k_temp=ElemenStiffness(i);
for j=1:2
for k=1:2
E_k(i,j,k)=E_k_temp(j,k);
end
end
end
I have in the Element Stiffness file
function ElementStiffness(element_no)
E_k(element_no);
ElementStiffness=E_k;
end
function Length
dimensions=size(E_C);
for i=1,dimensions(1)
node1=E_C(i,1);
node2=E_C(i,2);
x2=N_C(node2,1);
x1=N_C(node1,1);
y2=N_C(node2,2);
y1=N_C(node1,2);
z1=N_C(node1,3);
z2=N_C(node2,3);
Len(i,1)=(x2-x1)^2+(y2-y1)^2+(z2-z1)^2;
Len(i,1)=(Len(i,1))^0.5;
end
Length=Len;
end
function Jacobian(element_no)
len=Length;
% return Length(element_no,1)/2;
end
function NumberOfGaussPoints
n_dof=p+1;
q=max(2*p-1,2*p,p+2);
if (mod(q,2)==0)
NumberOfGaussPoints= q+2/2;
else
NumberOfGaussPoints= (q+1)/2;
end
end
function E_k(element_no)
for s=1:n_dof
for t=1:n_dof
k(s,t)=0;
end
for i=1,no_gp
all_gauss_pts_wts=SW(no_gp);
gauss_pt=all_gauss_pts_wts(i,1);
gauss_wt=all_gauss_pts_wts(i,2);
for s=1:n_dof
for t=1:n_dof
dN=LagrangianShapeFnsDerivatives(p,gauss_pt);
k(s,t)=k(s,t)+(dN(s,1)*dN(t,1)*A(element_no)*E(element_no)*(1/J));
end
end
end
end
E_k=k;
end
and then;
function SW=GaussPoints(no_gp)
SW := array(1..6,1..2);
if(no_gp==1)then
SW(1,1)=0;
SW(1,2)=2;
else if(no_gp==2)then
SW(1,1)=0.577350269189626;
SW(1,2)=1;
SW(2,1)=-0.577350269189626;
SW(2,2)=1;
else if(no_gp==3)then
SW(1,1)=0;
SW(1,2)=0.888888888888889;
SW(2,1)=0.774596669241483;
SW(2,2)=0.555555555555556;
SW(3,1)=-0.774596669241483;
SW(3,2)=0.555555555555556;
elseif (no_gp==4)then
SW(1,1)=0.339981043583856;
SW(1,2)=0.652145154862526;
SW(2,1)=-0.339981043583856;
SW(2,2)=0.652145154862526;
SW(3,1)=0.861136311590453;
SW(3,2)=0.3478548415137454;
SW(4,1)=-0.861136311590453;
SW(4,2)=0.3478548415137454;
else(no_gp==5)then
SW(1,1)=0.9061798459;
SW(1,2)=0.2369268851;
SW(2,1)=-0.9061798459;
SW(2,2)=0.2369268851;
SW(3,1)=0.5384693101;
SW(3,2)=0.5688888889;
SW(4,1)=-0.5384693101;
SW(4,2)=0.5688888889;
SW(5,1)=0;
SW(5,2)=0.1713244924;
end
When I compile the code, I get the following error in input file
>> Input_file
Error using ElementStiffness
Too many output arguments.
Error in Input_file (line 40) E_k_temp=ElementStiffness(i);
Also, the next file ElementStiffness has error
>> ElementStiffness(element_no) Undefined function or variable 'element_no'.
I really do not know what is the problem
I have attached my 3 .m files and the xls file. IF someone can help, I shall be extremely ever grateful.
0 件のコメント
回答 (1 件)
Walter Roberson
2015 年 7 月 29 日
In MATLAB, if you want to return a value from a variable, the syntax is not that you assign a value to the name of the function. Instead you use (for example)
function [ek] = ElementStiffness(element_no)
ek = E_k(element_no);
end
That is, you list the output variables on the left side of the "=" in the function statement, and you assign values to those output variables somewhere in your routine.
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!