# How can i correct this error ?

2 vues (au cours des 30 derniers jours)
Mallouli Marwa le 4 Août 2016
Hi
My problem is about a three node cantilever beam. I do a program that estimate the mass and stiffness matrix. c is an
output variable.
But, i obtain this error
Undefined function or variable "c". Error in fe_mk (line 79) if length(c)~=0 Error in prog_principle (line 31) [m,k,mdof]= fe_mk(node,elt,pl,il)
My priniciple program is :
format long g;
format compact;
% node# unused x y z
node=[1 0 0 0 0 0 0;
2 0 0 0 25.4e-03 0 0;
3 0 0 0 50.8e-03 0 0;
4 0 0 0 1 1 1];
elt=[
%declaration of elemnt groupe
Inf abs('beam1')
%node1 node2 pl il refnode
1 2 1 1 4 0 %longerons
2 3 1 1 4 0];
% matid matType E nu rho
pl=[ 1 1 10.5e+10 3.4e-01 9e+03];
% secId SecType J i1 i2 A
il=[ 1 1 3.75e-10 7.27e-15 3.75e-10 4.452e-06 ]; %longerons
%call of function
[m,k,mdof]= fe_mk(node,elt,pl,il)
And the fe_mk funtion is :
function [m,k,mdof]=fe_mk(node,elt,pl,il)
NNode = zeros(max(node(:,1)),1);NNode(node(:,1))=(1:length(node(:,1)))';
elseif nargin==7 && opt(1)==2 ty='ene';
elseif nargin==7 && opt(1)==1 ty='dmk';
elseif nargin==7 && opt(1)==0 ty='mka';
else disp ('not a valid value for opt(1)');
end
EGroup = [find(elt(:,1)==Inf)' size(elt,1)+1];
if strcmp(ty,'mka')&& nM==0
k = spalloc(size(node,1)*6,size(node,1)*6,size(elt,1)*100);
m = spalloc(size(node,1)*6,size(node,1)*6,size(elt,1)*100);
if nargout==4
c = spalloc(size(node,1)*6,size(node,1)*6,size(elt,1)*100);
end
elseif strcmp(ty,'mka')&& nM~=0
k = zeros(nM); m = zeros(nM);
if nargout == 4 c = zeros(nM); end
elseif strcmp(ty,'ene')&& nM~=0
m=zeros(size(elt,1),nM);
if nargout==2 c=m;end
elseif strcmp(ty,'ene')&& nM==0
error('Cannot compute energies without a mode');
elseif strcmp(ty,'dmk') && nM==0
if nA==0 error('adof is empty, cannot assemble group stiffness'); end
k = spalloc(nA*nGroup,nA,size(elt,1)*100);m=k;
if nargout == 4 c = k; end
elseif strcmp(ty,'dmk') && nM~=0
k = zeros(nM*nGroup,nM); m = k;
if nargout == 4 c = k; end
end
mdof = [];EDof = [];
if nGroup == 0 % backward compatibility for beam only model
elt = [Inf abs('beam1') zeros(1,size(elt,2)-6);
elt zeros(size(elt,1),size(elt,2)-6)];
nGroup = 1;EGroup = [find(elt(:,1)==Inf)' size(elt,1)+1];
end
% ----------------------------------------------------------------------------
% loop over element groups
for jGroup = 1:nGroup
ElemF = [find(elt(EGroup(jGroup),:)==0) size(elt,2)+1];
ElemF = deblank(setstr(elt(EGroup(jGroup),2:ElemF(1)-1)));
cEGI = EGroup(jGroup)+1:EGroup(jGroup+1)-1;
if exist(ElemF)==2
eval(['eCall=' ElemF '(1);'],'eCall=[];');
else eCall=[];end
for jElt=1:length(cEGI)
if exist(ElemF)==2
if isempty(eCall)
eval(['[m1,k1,i1] = ' ElemF ...
'(node,elt(cEGI(jElt),:),pl,il,[1 jGroup jElt]);']);
else eval([eCall ';'])
end
else disp([ElemF ' : unkwown element function']);
end
% --------------------------------------------------------------------------
if strcmp(ty,'mka')
%aa=clock;
ind = zeros(length(i1),1);for j2 = 1:length(i1)
i2 = find(mdof==i1(j2));
if isempty(i2) mdof = [mdof;i1(j2)];ind(j2)=length(mdof);
else ind(j2) = i2; end
end
%bb=[etime(clock,aa)];aa=clock;
k(ind,ind)=k(ind,ind)+k1;
m(ind,ind)=m(ind,ind)+m1;
if length(c)~=0
c(ind,ind)=c(ind,ind)+c1; end
else % selection of DOFs
in1=[];in2=[];for j2 = 1:length(i1)
i2 = find(mdof==i1(j2));
if isempty(i2)
if ~isempty(i2)
mdof = [mdof;i1(j2)];in1=[in1 length(mdof)];in2=[in2 j2];
end
else in1=[in1 i2];in2=[in2 j2]; end
end
k(in1,in1) = k(in1,in1)+k1(in2,in2);
m(in1,in1) = m(in1,in1)+m1(in2,in2);
if isempty(c) c(in1,in1) = c(in1,in1)+c1(in2,in2);end
end
if rem(cEGI(jElt),100)==0
disp(['Done ' num2str(cEGI(jElt)) ' elements']);
end
elseif strcmp(ty,'ene')
ind = zeros(length(i1),1);
for j2 = 1:length(i1) ind(j2) = find(adof==i1(j2)); end
in2 = find(ind~=0); ind = ind(in2);
if ~isempty(ind);for j2 = 1:size(mode,2);
if nargout>0
m(cEGI(jElt),j2) = mode(ind,j2)'*k1(in2,in2)*mode(ind,j2);
end
if nargout>1
c(cEGI(jElt),j2) = mode(ind,j2)'*m1(in2,in2)*mode(ind,j2);
end
end;end
if rem(cEGI(jElt),100)==0
disp(['Done ' num2str(cEGI(jElt)) ' elements']);
end
elseif strcmp(ty,'dmk')
ind = zeros(length(i1),1);
for j2 = 1:length(i1) ind(j2) = find(adof==i1(j2)); end
in2 = find(ind~=0); ind = ind(in2); if nM~=0 % projection of a basis of modes
k(jGroup*nM+[-nM+1:0],:) = k(jGroup*nM+[-nM+1:0],:) + ...
mode(ind,:)'*k1(in2,in2)*mode(ind,:);
m(jGroup*nM+[-nM+1:0],:) = m(jGroup*nM+[-nM+1:0],:) + ...
mode(ind,:)'*m1(in2,in2)*mode(ind,:);
if length(c)~=0
c(jGroup*nM+[-nM+1:0],:) = c(jGroup*nM+[-nM+1:0],:) + ...
mode(ind,:)'*c1(in2,in2)*mode(ind,:);
end
else % no projection
in3 = ind+nA*(jGroup-1);
m(in3,ind) = m(in3,ind)+ m1(in2,in2);
k(in3,ind) = k(in3,ind)+ k1(in2,in2);
if length(c)~=0 c(in3,ind) = c(in3,ind)+ c1(in2,in2);end
end
if rem(cEGI(jElt),100)==0
disp(['Done ' num2str(cEGI(jElt)) ' elements']);
end
end
end
% ----------------------------------------------------------------------------
end; % end loop on element groups
if strcmp(ty,'ene')
m=full(m(1:size(elt,1),1:size(mode,2)));
if nargout>1 c=full(c(1:size(elt,1),1:size(mode,2))); end
k=[];mdof=[];
elseif strcmp(ty,'mka')
[mdof,i1]=sort(mdof); [EDof,i2]=sort(EDof); i1 = [i1;i2];
k = k(i1,i1); m = m(i1,i1);
if ~isempty(c) c = c(i1,i1); end
mdof = [mdof;EDof];
if nargout==2 m=k;c=mdof; end
if nargout==3 c=k;k=mdof; end
elseif strcmp(ty,'dmk')
if nargout==2 m=k;c=mdof; end
if nargout==3 c=k;k=mdof; end
end
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur String Parsing dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by