Matlab解熱傳導方程代碼_第1頁
Matlab解熱傳導方程代碼_第2頁
Matlab解熱傳導方程代碼_第3頁
Matlab解熱傳導方程代碼_第4頁
全文預覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

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),

2、title(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); p

3、lot(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);

4、dx = 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 c

5、onduction),%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

6、; %leftt(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); end精品.subplot(2,1,1),contour(x

7、,y,t),title(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,

8、13,n);u = 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-u

9、old); if 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),hol

10、d 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 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

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論