⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dirich.m

📁 国外计算机科学教材系列 numerial method using matlab (third edition)
💻 M
字号:
function U=dirich(f1,f2,f3,f4,a,b,h,tol,max1)%      U=dirich('f1','f2','f3','f4',4,4,0.5,0.001,3)%Input - f1,f2,f3,f4 are boundary functions input as strings%      - a and b right endpoints of [0,a] and [0,b]%      - h step size%      - tol is the tolerance%Output - U solution matrix; analogous to Table 10.6%Initialize parameters and U% NUMERICAL METHODS: MATLAB Programs%(c) 1999 by John H. Mathews and Kurtis D. Fink%To accompany the textbook:%NUMERICAL METHODS Using MATLAB,%by John H. Mathews and Kurtis D. Fink%ISBN 0-13-270042-5, (c) 1999%PRENTICE HALL, INC.%Upper Saddle River, NJ 07458n=fix(a/h)+1;m=fix(b/h)+1;ave=(a*(feval(f1,0)+feval(f2,0)) ...   +b*(feval(f3,0)+feval(f4,0)))/(2*a+2*b);U=ave*ones(n,m);%Boundary conditionsU(1,1:m)=feval(f3,0:h:(m-1)*h)';U(n,1:m)=feval(f4,0:h:(m-1)*h)';U(1:n,1)=feval(f1,0:h:(n-1)*h);U(1:n,m)=feval(f2,0:h:(n-1)*h);U(1,1)=(U(1,2)+U(2,1))/2;U(1,m)=(U(1,m-1)+U(2,m))/2;U(n,1)=(U(n-1,1)+U(n,2))/2;U(n,m)=(U(n-1,m)+U(n,m-1))/2;%SOR parameterw=4/(2+sqrt(4-(cos(pi/(n-1))+cos(pi/(m-1)))^2));%Refine approximations and sweep operator throughout the griderr=1;cnt=0;while((err>tol)&(cnt<=max1))   err=0;   for j=2:m-1      for i=2:n-1         relx=w*(U(i,j+1)+U(i,j-1)+U(i+1,j)+U(i-1,j)-4*U(i,j))/4;         U(i,j)=U(i,j)+relx;         if (err<=abs(relx))           err=abs(relx);         end      end      endcnt=cnt+1;endU=flipud(U');function e1=f1(t)e1=0;function e2=f2(t)e2=180;function e3=f3(t)e3=80;function e4=f4(t)e4=0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -