您好,欢迎访问三七文档
有限元法课程作业(二):一维问题的有限元方法一、解题步骤:将原问题的边界齐次化:0u(1)0,u(0))(-4uu-1eexxex’’’1)单元剖分:),400,2,1(niei;2)i=1~~00Ab;3)计算数值积分:()()()()()()1,11,,1,1,,,,,iiiiiiiiiiiiiiiiaaaabb即得单元上的iiAb;4)将iiAb迭加到总的~~Ab中;5)若i=n,则i=i+1并转到底三步;否则继续下一步;6)根据边界条件调整~~Ab(掐头去尾),即得A和b;7)解线性方程组Au=b,得u从而的hu。二、程序编写主程序:function[]=main(n)n=400;%对x的随机剖分及区间长度的计算l=abs(rand(1,n-1));fori=1:n-1forj=(i+1):n-1ifl(i)l(j)l2=l(i);l(i)=l(j);l(j)=l2;endendendfori=1:n-1x(i+1)=l(i);endx(1)=0;x(n+1)=1;fori=1:nh(i)=x(i+1)-x(i);end%一次区间元法%A的求解fori=1:na(i,1)=1/h(i)+h(i)/3;a(i,2)=-1/h(i)+h(i)/6;a(i,3)=a(i,2);a(i,4)=a(i,1);endfori=1:n-1A(i,i)=a(i,4)+a(i+1,1);endfori=1:n-2A(i,i+1)=a(i+1,2);endfori=2:n-1A(i,i-1)=a(i,3);End%b的求解fori=2:n+1b1(i,i-1)=f1(x(i-1),h(i-1));b1(i,i)=f2(x(i-1),h(i-1));endfori=2:nb2(i)=b1(i,i)+b1(i+1,i);endfori=1:n-1b(i)=b2(i+1);endu=inv(A)*b';fori=2:nun(i)=u(i-1);endun(1)=0;un(n+1)=0;%还原原始的u值uz=un'+x'*(exp(1)-exp(-1));Uz%真解的求解fori=1:n+1u1(i)=exp(x(i))-exp(-x(i))+x(i)*x(i)*exp(x(i))-x(i)*exp(x(i));endu1'%误差的计算fori=1:n+1e(i)=abs((uz(i)-u1(i))/u1(i)*100);ende'%作图subplot(1,2,1)plot(x,u1)xlabel('自变量x的范围');ylabel('函数值u的取值');title('真解的图象');gridsubplot(1,2,2)plot(x,uz)xlabel('自变量x的范围');ylabel('函数值u的取值');title('有限元法算得的近似解的图象');Grid两个子程序编写:function[y1]=f1(x,h)y1=h*(1/6*(-24*exp(x+h)*h-3*h^2*exp(1)*x+48*exp(x+h)-24*exp(x+h)*x-h^3*exp(1)+3*h^2*exp(-1)*x+h^3*exp(-1)+24*exp(x)*h*x-48*exp(x)-24*exp(x)*h+24*x*exp(x))/h^2);function[y2]=f2(x,h)y2=h*(1/6*(48*exp(x+h)*h-24*exp(x+h)*h^2-24*exp(x+h)*x*h-3*h^2*exp(1)*x+3*h^2*exp(-1)*x-2*h^3*exp(1)+2*h^3*exp(-1)+24*exp(x+h)*x-48*exp(x+h)-24*x*exp(x)+48*exp(x))/h^2);三、MATLAB程序运行结果图1:理论值与有限元法近似值图表1:理论值与有限元法近似值表理论值有限元法近似值误差(100%)理论值有限元法近似值误差(100%)0000.6680.66800.01440.014400.6850.68500.01720.017200.70450.704500.03030.030300.70740.707400.03550.035500.71360.713600.05080.050800.72960.72970.01370.05230.052300.79080.790800.05610.056100.79340.79350.01260.05750.057500.83570.835700.05920.059200.84330.843300.05930.059300.84360.843600.06640.066400.8990.89900.06840.06850.14620.9060.90600.07390.073900.90780.90790.01100.08590.085900.92510.925100.09520.095200.9590.95900.10910.109100.9610.96100.11520.115200.96280.96290.01040.11520.115201.0691.06910.00940.1730.17301.0781.07800.18510.185101.08361.08370.00920.20720.207201.09671.096700.21510.215101.10161.101600.22110.221101.17371.17380.00850.22940.229401.21841.218400.23940.239401.25321.253200.24080.240801.2671.26710.00790.24150.241501.33151.331500.27620.276201.36011.36020.00740.2950.29501.38421.384200.30280.302801.40621.406200.31840.318401.441.4400.33950.339501.48291.482900.35870.358701.531.5300.36480.364801.60821.608200.36910.369101.6751.67500.38510.385101.70761.707600.41720.417201.73091.730900.47520.475201.74181.741800.50550.505501.78621.786200.53310.53320.01881.89821.898200.53350.533501.95671.956700.53990.539902.03422.034200.5440.54402.05972.059700.54560.545602.0962.09600.55870.558702.10972.109700.55910.559102.12082.120800.56990.569902.13912.139100.64260.642602.2292.22900.65580.65590.01522.35042.350400.66710.66710四、数据分析结论MATLAB仿真实验表明:1)当n=100时,理论值与有限元法近似值非常接近,其误差最大值是0.0137%;2)当n=30时,误差最大值是0.0094%;当n=200时,误差最大值是0.075%,分析表明该有限元方法,精度并不随着n值得变大而提高;3)通过以上分析,该有限元法近似值近似精度较高,可以作为求值的近似,有一定的实用意义。
本文标题:有限元法课程作业
链接地址:https://www.777doc.com/doc-2321332 .html