Matlab解热传导方程代码.doc

上传人:灯火****19 文档编号:136109614 上传时间:2020-06-24 格式:DOC 页数:3 大小:24KB
返回 下载 相关 举报
Matlab解热传导方程代码.doc_第1页
第1页 / 共3页
Matlab解热传导方程代码.doc_第2页
第2页 / 共3页
Matlab解热传导方程代码.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《Matlab解热传导方程代码.doc》由会员分享,可在线阅读,更多相关《Matlab解热传导方程代码.doc(3页珍藏版)》请在金锄头文库上搜索。

1、Sample MATLAB codes 1.%Newton Cooling Lawclear; close all; clc; h = 1;T(1) = 10; %T(0)error = 1;TOL = 1e-6;k = 0;dt = 1/10;while error TOL, k = k+1; T(k+1) = h*(1-T(k)*dt+T(k); error = abs(T(k+1)-T(k);endt = linspace(0,dt*(k+1),k+1); plot(t,T),hold on, plot(t,1,r-.)xlabel(Time),ylabel(Temperature),t

2、itle(T_0 = ,num2str(T(1), , T_infty = 1),legend(Cooling Trend,Steady State)2.%Boltzman Cooling Lawclear; close all; clc; h = 1;T(1) = 10; %T(0)error = 1;TOL = 1e-6;k = 0;dt = 1/10000;while error TOL, k = k+1; T(k+1) = h*(1-(T(k)4)*dt+T(k); error = abs(T(k+1)-T(k); endt = linspace(0,dt*(k+1),k+1); pl

3、ot(t,T),hold on, plot(t,1,r-.)xlabel(Time),ylabel(Temperature),title(T_0 = ,num2str(T(1), , T_infty = 1),legend(Cooling Trend,Steady State)3.%Fourier Heat conduction clear; close all; clc; h = 1;n = 11;T = ones(n,1); Told = T;T(1) = 1; %Left boundaryT(n) = 10; %Right boundaryx = linspace(0,1,n);dx =

4、 x(2)-x(1);dt = dx2/3; %cfl condition error = 1;TOL = 1e-6;k = 0;while error TOL, Told = T; k = k+1; for i = 2:n-1 T(i) = dt*(Told(i+1)-2*Told(i)+Told(i-1)/dx2+Told(i); end error = max(abs(T-Told); if mod(k,5)=0, out(k,:) = T; end end plot(x,out)xlabel(x),ylabel(Temperature),title(Fourier Heat Condu

5、ction),%legend(Cooling Trend,Steady State)4. 2D Heat Equation%2D Heat Equation.clear; close all; clcn = 10; %grid has n - 2 interior points per dimension (overlapping)x = linspace(0,1,n); dx = x(2)-x(1); y = x; dy = dx;TOL = 1e-6; T = zeros(n);T(1,1:n) = 10; %TOPT(n,1:n) = 1; %BOTTOMT(1:n,1) = 1; %L

6、EFTT(1:n,n) = 1; %RIGHTdt = dx2/4;error = 1; k = 0; while error TOL k = k+1; Told = T; for i = 2:n-1 for j = 2:n-1 T(i,j) = dt*(Told(i+1,j)-2*Told(i,j)+Told(i-1,j)/dx2 . + (Told(i,j+1)-2*Told(i,j)+Told(i,j-1)/dy2) . + Told(i,j); end end error = max(max(abs(Told-T); endsubplot(2,1,1),contour(x,y,T),t

7、itle(Temperature (Steady State),xlabel(x),ylabel(y),colorbarsubplot(2,1,2),pcolor(x,y,T),shading interp,title(Temperature (Steady State),xlabel(x),ylabel(y),colorbar5. Wave Translation%Oscillations - translation left and right clear; close all; clc; for c = 1 -1cc = 0;n = 261; x = linspace(0,13,n);u

8、 = zeros(n,1);u(121:141) = sin(pi*x(121:141);dx = x(2)-x(1);dt = dx;error = 1;TOL = 1e-6;k = 0;while k 110 uold = u; k = k+1; for i = 2:n-1 if c = 1, u(i) = dt*c*(uold(i+1)-uold(i)/dx+uold(i); end %c = 1 if c = -1, u(i) = dt*c*(uold(i)-uold(i-1)/dx+uold(i); end %c = -1 end error = max(abs(u-uold); i

9、f mod(k,10)=0, cc = cc+1; out(cc,:) = u; end end if c = 1subplot(2,1,1),for hh = 1:ccplot(x,out(hh,:)+hh),hold on,endu = zeros(n,1);u(121:141) = sin(pi*x(121:141); plot(x,u)xlabel(u(x),ylabel(Time),title(Translation to the Left)elseif c = -1subplot(2,1,2),for hh = 1:ccplot(x,out(hh,:)+hh),hold on,en

10、du = zeros(n,1);u(121:141) = sin(pi*x(121:141); plot(x,u)xlabel(u(x),ylabel(Time),title(Translation to the Right)endend6.%wave equationclear; close all; clc;c = 1;n = 21; x = linspace(0,1,n); dx = 1/(n-1);dt = dx;u(:,1) = sin(pi*x);u(1,2) = 0;for i = 2:n-1u(i,2) = 0.5*(dt2*c2*(u(i+1,1)-2*u(i,1)+u(i-1,1)/dx2+2*u(i,1);endu(n,2) = 0;error = 1; k = 1;while k 100 k = k+1; u(1,k+1) = 0; for i = 2:n-1 u(i,k+1) = dt2*c2*(u(i+1,k)-2*u(i,k)+u(i-1,k)/dx2+2*u(i,k)-u(i,k-1); end u(n,k+1) = 0;endplot(x,u), xlabel(x),ylabel(y)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号