일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 힙
- Navier-Stokes
- Boundary Layers
- Statistics
- 프로젝트오일러
- Turbulent
- 우선순위큐
- Finite Difference Method
- 프로그래머스
- 파이썬
- Blasius
- Compressible Flow
- Python
- python3
- Fluid Dynamics
- FTCS
- heap
- 통계학
- Crank-Nicolson
- 유체역학
- Laminar
- 이중우선순위큐
- projecteuler
- Heat Equation
- 디스크 컨트롤러
- programmers
- 예제
- regression
- 회귀
- Fluids
- Today
- Total
Sudal's Garage
MATLAB, pause를 이용한 움직이는 그래프, animation using pause 본문
앞서 포스팅한 heatFTCS function을 이용해 시간에 따른 온도변화를 시각적으로 나타내보자
function animate1D 를 구현하자
% U: Matrix created by heatFTCS function % tf: Final time value used in heatFTCS function % L: Length L % speedx: run the animation x speed fast function animate1D(U,tf,L,speedx) [m,n] = size(U); X = linspace(0,L,m); % narrow down the number of column of U since its too slow having too % many data to draw I = 1:round(sqrt(n)/2):n; colormap jet set(gca,'YTick', []) % off y axis xlabel('Length') % x label xlim([0 L]); % x axis limit colorbar; % put colorbar caxis([min(min(U)) max(max(U))]) % set colorbar limit hold on; for i = I title(['Temperature distribution at t = ', num2str(i*tf/n),'s']) % title imagesc(X,[],U(:,i)') pause(tf/length(I)/speedx) % show n/tf frames in 1 second end title(['Temperature distribution at t = ', num2str(tf),'s']) % title imagesc(X,[],U(:,end)') end
Input:
U: heatFTCS 함수의 Output Matrix
tf: final time value
L: Length L
speedx: 배속설정. 2배속이면 2를 넣어준다
U Matrix 의 사이즈를 m과 n에 저장해준다.
X 는 x(displacement)를 나타내어 주기위한 U와 같은 길이의 vector
[m,n] = size(U); X = linspace(0,L,m);
U 의 Column은 같은 시간동안의 각 위치의 온도에 대한 데이터를 저장하고 있다.
모든 column의 데이터를 그래프화하면 시간이 너무 오래 걸림으로, column의 수에 다라 적당히 그래프화 시킬 데이터 set을 정해준다
I = 1:round(sqrt(n)/2):n;
Figure Property 를 설정해 주자
colormap jet set(gca,'YTick', []) % y축 설정
xlabel('Length') % x 축 제목
xlim([0 L]); % x 축 범위
colorbar; % 색표 추가
caxis([min(min(U)) max(max(U))]) % 색표 범위를 설정한다
hold on;
I(end) = n;
아래 스크립트를 실행:
alpha = 0.1; L = 1; tf = 50;
F = @(x) zeros(size(x)); G0 = @(t) sin(1.2*t); GL = @(t) -2*sin(0.5*t);
h = 0.01; k = 0.0005;
U = heatFTCS(alpha,L,G0,GL,F,h,k,tf);
animate1D(U,tf,L,1)
result:
'Programming > MATLAB' 카테고리의 다른 글
Second order regression (0) | 2019.03.19 |
---|---|
Finite Differential Method for the Heat Equation, CN Method (0) | 2019.03.16 |
FTCS Method 의 Stability (0) | 2019.02.28 |
Finite Difference Method for the Heat Equation, FTCS Method (0) | 2019.02.27 |
MATLAB, implicit Euler Method, Global Truncation Error, BVPs, Fourier Transform (0) | 2019.02.16 |