按花主任的说法我把程序贴出来了,帮看看问题出那边吧
%mainprogram
global node element K E t mu
node_number=input('input node number:');
node=zeros(node_number,2);
node=input('input coordinates of the node');
element_number=input('input element number:');
element=zeros(element_number,4);
element=input('input element') ;
bc_number=input('input number of boundary condition');
bc=zeros(bc_number,3);
bc=input('input boundary condition:');
nf_number=input('input number of node force');
nf=zeros(nf_number,3);
nf=input('input node force');
E=input('input Yang’s modulus');
t=input('input thickness');
mu=input('input Poisson’s ratio');
K=sparse(node_number*2,node_number*2);
f=sparse(node_number*2,1);
for ie=1:element_number;
k=stiffnessmatrix(ie,E,t,mu);
assemblestiffnessmatrix(ie,k);
end;
for inf=1:nf_number;
n=nf(inf,1);
d=nf(inf,2);
f(((n-1)*2+d),1)=nf(inf,3);
end ;
for ibc=1:bc_number
n=bc(ibc,1)
d=bc(ibc,2)
m=(n-1)*2+d
f(m)=bc(ibc,3)*K(m,m)*1e15
K(m,m)=K(m,m)*1e15
end
delta=K\f
el=input('input element number you choose:');
d=zeros(3,6);
b=zeros(3,1);
c=zeros(3,1);
b(1)=node(element(el,2),2)-node(element(el,3),2);
c(1)=node(element(el,3),1)-node(element(el,2),1);
b(2)=node(element(el,3),2)-node(element(el,1),2);
c(2)=node(element(el,1),1)-node(element(el,3),1);
b(3)=node(element(el,1),2)-node(element(el,2),2);
c(3)=node(element(el,2),1)-node(element(el,1),1);
A=(b(1)*c(2)-b(2)*c(1))*0.5;
chang1=E*t/(2*(1-mu^2)*A);
dl=zeros(6,1);
dl(1)=delta(((element(el,1)-1)*2+1),1);
dl(2)=delta(((element(el,1)-1)*2+2),1);
dl(3)=delta(((element(el,2)-1)*2+1),1);
dl(4)=delta(((element(el,2)-1)*2+2),1);
dl(5)=delta(((element(el,3)-1)*2+1),1);
dl(6)=delta(((element(el,3)-1)*2+2),1);
for i=1:3
d(1,(i-1)*2+1)=b(i)*chang1;
d(1,(i-1)*2+2)=mu*c(i)*chang1;
d(2,(i-1)*2+1)=mu*b(i)*chang1;
d(2,(i-1)*2+2)=c(i)*chang1;
d(3,(i-1)*2+1)=0.5*(1-mu)*c(i)*chang1;
d(3,(i-1)*2+2)=0.5*(1-mu)*b(i)*chang1;
end
stress=d*dl
%刚度矩阵
function k=stiffnessmatrix(ie,E,t,mu)
global node element E t mu
k=zeros(6,6)
b=zeros(3,1)
c=zeros(3,1)
b(1)=node(element(ie,2),2)-node(element(ie,3),2)
c(1)=node(element(ie,3),1)-node(element(ie,2),1)
b(2)=node(element(ie,3),2)-node(element(ie,1),2)
c(2)=node(element(ie,1),1)-node(element(ie,3),1)
b(3)=node(element(ie,1),2)-node(element(ie,2),2)
c(3)=node(element(ie,2),1)-node(element(ie,1),1)
A=(b(1)*c(2)-b(2)*c(1))*0.5
chang=E*t/(4*(1-mu^2)*A)
for i=1:3
for j=1:3
m1=(i-1)*2+1
m2=(i-1)*2+2
n1=(j-1)*2+1
n2=(j-1)*2+2
k(m1,n1)=chang*(b(i)*b(j)+0.5*(1-mu)*c(i)*c(j))
k(m1,n2)=chang*(b(i)*c(j)*mu+0.5*(1-mu)*c(i)*b(j))
k(m2,n1)=chang*(b(j)*c(i)*mu+0.5*(1-mu)*c(j)*b(i))
k(m2,n2)=chang*(c(i)*c(j)+0.5*(1-mu)*b(i)*b(j))
end
end
return
%组合
function assemblestiffnessmatrix(ie,k)
global element K
for i=1:1:3
for j=1:1:3
for p=1:1:2
for q=1:1:2
m=(i-1)*2+p
n=(j-1)*2+q
M=(element(ie,i)-1)*2+p
N=(element(ie,j)-1)*2+q
K(M,N)=K(M,N)+k(m,n)
end
end
end
end
return
要输入的参数
input node number:6
input coordinates of the node[0 0;1 0;2 0;0 1;1 1;1 2]
input element number:4
input element[1 1 5 4;2 1 2 5;3 2 6 5;4 2 3 6]
input number of boundary condition3
input boundary condition:[1 1 0;1 2 0;4 1 0]
input number of node force1
input node force[6 1 1]
input Yang’s modulus1.0e+6
input thickness0.1
input Poisson’s ratio0.3
运行出现了如下的结果:
delta =
(1,1) NaN
(2,1) NaN
(3,1) NaN
(4,1) NaN
(5,1) NaN
(6,1) NaN
(7,1) NaN
(8,1) NaN
(9,1) NaN
(10,1) NaN
(11,1) NaN
(12,1) NaN
input element number you choose:1
Warning: Divide by zero.
(Type "warning off MATLAB:divideByZero" to suppress this warning.)
> In C:\Documents and Settings\small_bridge\桌面\有限元\mainpro3.m at line 48
stress =
NaN
NaN
NaN
[ 本帖最后由 xyxyclq 于 2007-7-22 13:30 编辑 ] |