找回密码
 注册
Simdroid-非首页
查看: 339|回复: 4

matlab有限差分法

[复制链接]
发表于 2006-8-15 11:09:48 | 显示全部楼层 |阅读模式 来自 河南郑州
有兄弟用过有限差分法吗??
小弟想找几个算例看看。
谢谢!
发表于 2006-8-15 13:56:19 | 显示全部楼层 来自 江苏无锡

参考参考吧

Simdroid开发平台
function cranknicolson
%This program is used to solve Partial Differential Equation by Finite Difference Formulation of Crank Nicolson Method
clc
clear
%confirm a, a has relation to time unit and quality unit,length unit
%in this program,time unit is year ,length unit is mm,quality unit is kg
hold on        %绘制的图形曲线保持,与下面运行的图形同时出现在一个图面内
a=1*1e-6*24*3600*365;    %扩散系数为常数
cs=17.7*10^9;
day=400;                        %时间,单位为年
t=200;                                %时间步长
n=day/t;                        %时间网格划分,时间步数
length=200;                %试件长度
h=20;                        %空间步长
m=length/h;                %空间网格划分
ss=a*t/(h*h);        %步长比
r=m-1;                        %空间步数
%conform coefficient matrix aaleft and bbright
aa=zeros(r,r);        %系数矩阵aa置零
bb=zeros(r,r);        %系数矩阵bb置零

%以下形成系数矩阵aa
for i=1:r
    aa(i,i)=1+ss;
end
for i=1:r-1
    aa(i,i+1)=-0.5*ss;
end
for i=2:r
    aa(i,i-1)=-0.5*ss;
end

%以下形成系数矩阵bb
for i=1:r
   bb(i,i)=1-ss;
end
for i=1:r-1
    bb(i,i+1)=0.5*ss;
end
for i=2:r
    bb(i,i-1)=0.5*ss;
end

%时间步为1时对应数值求解
u0=zeros(m-1,1);
for i=1:m-1
    u0(i)=0;
end
mul=bb*u0;
bb0=ss*0.5*(cs+cs);
bb1=ss*0.5*(0+0);
mul(1)=mul(1)+bb0;
mul(m-1)=mul(m-1)+bb1;
%trsolve is a private program used to solve three diagonal equations
u(:,1)=aa\mul;

%三对角矩阵求解
for i=1:n-1
     bb0=ss*0.5*(cs+cs);
     bb1=ss*0.5*(0+0);
    mul=bb*u(:,i);
    mul(1)=mul(1)+bb0;
    mul(m-1)=mul(m-1)+bb1;
    u(:,i+1)=aa\mul;
end

%结果可视化
u=u/10^9;
plv=[cs/10^9 u(:,n)' 0];
plh=0:h:length;
plot(plh,plv);
grid on
xlabel('Concrete Cover(mm)')
ylabel('Cf(kg/m^3)  Pore Solution')

%结果存入文件crfifty.txt
% save crfifty.txt plv plh -ascii
 楼主| 发表于 2006-8-15 15:15:29 | 显示全部楼层 来自 河南郑州
谢谢楼上的
楼上的能给出对应的待求的微分方程的形式吗??
发表于 2011-11-25 16:35:14 | 显示全部楼层 来自 广东深圳
:):(:D:P:L
回复 不支持

使用道具 举报

发表于 2011-11-25 16:40:12 | 显示全部楼层 来自 广东深圳
谢谢···················
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-10-6 07:56 , Processed in 0.035777 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表