ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf,...

18

Transcript of ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf,...

Page 1: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:
Page 2: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:
Page 3: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

ME 565 Spring 2019 - HW 3, Problem 2AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver: 9.2.0.556344 (R2017a) FILENAME : hw3_2.m

clear all; close all;

xmax = 300;ymax = 300;% itmax = 18000;itmax = 18000;no_images = 4;u = zeros(xmax,ymax);u3 = u;x = linspace(-1.5,1.5,xmax);y = linspace(-1.5,1.5,ymax);it = 0;% case 1u(:,:) = 2;u(:,1:end/2) = 1;ui = u;u2 = u;f2c1 = ': Cross-section of Case 1 (zero initial condition)';f2c2 = 'at time iterations t1=1, t2=6000, t3=12000, t4=18000';fig2cap = sprintf('%s%s',f2c1,f2c2);f1c1 = ': Two dimensional maps for Case 1 (zero initial condition)';fig1cap = sprintf('%s%s',f1c1,f2c2);f4c1 = ': Cross-section of Case 2 (top/bottom initial condition)';fig4cap = sprintf('%s%s',f4c1,f2c2);f3c1 = ': Two dimensional maps for Case 2 (top/bottom initial condition)';fig3cap = sprintf('%s%s',f3c1,f2c2);f6c1 = ': Cross-section of Case 3 (cos(theta) boundary condition)';fig6cap = sprintf('%s%s',f6c1,f2c2);f5c1 = ': Two dimensional maps for Case 3 (cos(theta) boundary condition)';fig5cap = sprintf('%s%s',f5c1,f2c2);% case 2for ii=1:1:xmax for jj=1:1:ymax theta = atan2(y(jj),x(ii)); u3(ii,jj) = cos(theta); endendui3 = u3;mid_mat = zeros(no_images,ymax);image_mat = zeros(no_images,xmax,ymax);mid_mat2 = zeros(no_images,ymax);image_mat2 = zeros(no_images,xmax,ymax);mid_mat3 = zeros(no_images,ymax);image_mat3 = zeros(no_images,xmax,ymax);count = 1;

1

Page 4: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

save_stop = floor(linspace(1,itmax,no_images));for it=1:itmax for i=1:1:xmax for j=1:1:ymax if ((x(i)^2+y(j)^2)>1.5) u(i,j) = ui(i,j); u2(i,j) = ui(i,j); u3(i,j) = ui3(i,j); elseif ((x(i)^2+y(j)^2)<=1.5)&&it==1 u(i,j) = 0; u3(i,j) = 0; if i>=ymax/2; u2(i,j) = -1; else u2(i,j) = 1; end end end end

% if (mod(it,itmax/10)==0)||it==1% if it==1% imagesc(u2);% colorbar;% colormap('gray')% title('Case 1 initial condition')% drawnow;% figure(10)% imagesc(flipud(u3));% colorbar;% colormap('gray')% title('Case 2 initial condition')% % set(gca,'xdir','reverse')% drawnow;% end if it==save_stop(count) mid_mat(count,:) = u(end/2,:); image_mat(count,:,:) = u(:,:); mid_mat2(count,:) = u2(end/2,:); image_mat2(count,:,:) = u2(:,:); mid_mat3(count,:) = u3(:,end/2); image_mat3(count,:,:) = u3(:,:); count = count + 1; end Lu = del2(u); u(2:xmax-1,2:ymax-1) = u(2:xmax-1,2:ymax-1) + Lu(2:xmax-1,2:ymax-1); Lu2 = del2(u2); u2(2:xmax-1,2:ymax-1) = u2(2:xmax-1,2:ymax-1) + Lu2(2:xmax-1,2:ymax-1); Lu3 = del2(u3); u3(2:xmax-1,2:ymax-1) = u3(2:xmax-1,2:ymax-1) + Lu3(2:xmax-1,2:ymax-1);end

2

Page 5: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

figure(2)title('plot of Case 1, zero initial condition')subplot(2,2,1); imagesc(squeeze(image_mat(1,:,:))); colorbar;axis('square'); title('Initial'); caxis([0 2]);subplot(2,2,2); imagesc(squeeze(image_mat(2,:,:))); colorbar;axis('square'); title('~Beginning'); caxis([0 2]);subplot(2,2,3); imagesc(squeeze(image_mat(3,:,:))); colorbar;axis('square'); title('~Mid'); caxis([0 2]);subplot(2,2,4); imagesc(squeeze(image_mat(4,:,:))); colorbar;axis('square'); title('~Steady State'); caxis([0 2]);snapnowdisp(['Figure ' num2str(1) fig1cap])

figure(3)hold on;plot(x,mid_mat(1,:),'k-','linewidth',2.0);plot(x,mid_mat(2,:),'r-.','linewidth',2.0);plot(x,mid_mat(3,:),'r:','linewidth',2.0);plot(x,mid_mat(4,:),'k--','linewidth',2.0);legend('Initial t1','t2','t3','t4')snapnowdisp(['Figure ' num2str(2) fig2cap])% title('Cross-section of Case 1 at different times')

figure(4)title('plot of Case 1, [-1,1] initial condition')subplot(2,2,1); imagesc(flipud(squeeze(image_mat2(1,:,:)))); colorbar;axis('square'); title('Initial'); caxis([-1 2]);subplot(2,2,2); imagesc(flipud(squeeze(image_mat2(2,:,:)))); colorbar;axis('square'); title('~Beginning'); caxis([-1 2]);subplot(2,2,3); imagesc(flipud(squeeze(image_mat2(3,:,:)))); colorbar;axis('square'); title('~Mid'); caxis([-1 2]);subplot(2,2,4); imagesc(flipud(squeeze(image_mat2(4,:,:)))); colorbar;axis('square'); title('~Steady State'); caxis([-1 2]);snapnowdisp(['Figure ' num2str(3) fig3cap])

figure(5)hold on;plot(x,mid_mat2(1,:),'k-','linewidth',2.0);plot(x,mid_mat2(2,:),'r-.','linewidth',2.0);plot(x,mid_mat2(3,:),'r:','linewidth',2.0);plot(x,mid_mat2(4,:),'k--','linewidth',2.0);legend('Initial t1','t2','t3','t4')snapnowdisp(['Figure ' num2str(4) fig4cap])% title('Cross-section of Case 1, with initial conditions, at different times')

figure(7)title('plot of Case 2, zero initial condition')subplot(2,2,1); imagesc(flipud(squeeze(image_mat3(1,:,:)))); colorbar;axis('square'); title('Initial'); caxis([-1 1]);

3

Page 6: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

subplot(2,2,2); imagesc(flipud(squeeze(image_mat3(2,:,:)))); colorbar;axis('square'); title('~Beginning'); caxis([-1 1]);subplot(2,2,3); imagesc(flipud(squeeze(image_mat3(3,:,:)))); colorbar;axis('square'); title('~Mid'); caxis([-1 1]);subplot(2,2,4); imagesc(flipud(squeeze(image_mat3(4,:,:)))); colorbar;axis('square'); title('~Steady State'); caxis([-1 1]);snapnowdisp(['Figure ' num2str(5) fig5cap])

figure(6)hold on;plot(x,mid_mat3(1,:),'k-','linewidth',2.0);plot(x,mid_mat3(2,:),'r-.','linewidth',2.0);plot(x,mid_mat3(3,:),'r:','linewidth',2.0);plot(x,mid_mat3(4,:),'k--','linewidth',2.0);legend('Initial t1','t2','t3','t4')snapnowdisp(['Figure ' num2str(6) fig6cap])% title('Cross-section of Case 2 at different times')

Figure 1: Two dimensional maps for Case 1 (zero initial condition)at time iterations t1=1, t2=6000, t3=12000, t4=18000

4

Page 7: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

Figure 2: Cross-section of Case 1 (zero initial condition)at time iterations t1=1, t2=6000, t3=12000, t4=18000

5

Page 8: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

Figure 3: Two dimensional maps for Case 2 (top/bottom initial condition)at time iterations t1=1, t2=6000, t3=12000, t4=18000

6

Page 9: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

Figure 4: Cross-section of Case 2 (top/bottom initial condition)at time iterations t1=1, t2=6000, t3=12000, t4=18000

7

Page 10: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

Figure 5: Two dimensional maps for Case 3 (cos(theta) boundary condition)at time iterations t1=1, t2=6000, t3=12000, t4=18000

8

Page 11: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

Figure 6: Cross-section of Case 3 (cos(theta) boundary condition)at time iterations t1=1, t2=6000, t3=12000, t4=18000

Published with MATLAB® R2017a

9

Page 12: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:
Page 13: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:
Page 14: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:
Page 15: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

% First 100 An and Bn Coefficients% Follows Professor Brunton's L12_Fourier.m code

clear all, close all, clc

dx = 0.01;L = 2;x = (-L):dx:L;

f = ones(size(x));

% Build the Rectangular Wavef(1:length(f)/4) = 0*f(1:length(f)/4);f(length(f)/4:3*length(f)/4) = f(length(f)/4:3*length(f)/4);f(3*length(f)/4:length(f)) = 0*f(3*length(f)/4:length(f));

fFS = zeros(size(x));% Fourier Series A0A0 = (1/(2*L))*sum(f.*ones(size(x)))*dx;

Am = zeros(1,100);Bm = zeros(1,100);

for n=1:100 % Fourier An and Bn Coefficients An = (1/L)*sum(f.*cos((pi*n*x)/L))*dx; Bn = (1/L)*sum(f.*sin((pi*n*x)/L))*dx; Am(n) = sum(An); Bm(n) = sum(Bn); end fi = figure;stem(1:100,Am) hold onstem(1:100,Bm,'--')xlabel('Mode')ylabel('Mode Value')title('Exercise 3-3 100 Mode Coefficients')legend('An','Bn') % Approximation Using n=10 and 0.01 for Plots% Follows Professor Brunton's L12_Fourier.m code

clear all, clc

dx = 0.01;L = 2;x = (-L):dx:L;

f = ones(size(x));

% Build the Rectangular Wavef(1:length(f)/4) = 0*f(1:length(f)/4);f(length(f)/4:3*length(f)/4) = f(length(f)/4:3*length(f)/4);f(3*length(f)/4:length(f)) = 0*f(3*length(f)/4:length(f));

fFS = zeros(size(x));% Fourier Series A0A0 = (1/(2*L))*sum(f.*ones(size(x)))*dx;

for m=1:10 fFS = A0;

Page 16: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:

for n=1:m % Fourier An and Bn Coefficients An = (1/L)*sum(f.*cos((pi*n*x)/L))*dx; Bn = (1/L)*sum(f.*sin((pi*n*x)/L))*dx; fFS = fFS + An*cos((n*pi*x)/L) + Bn*sin((n*pi*x)/L); end end

fi = figure;plot(x,f)hold onplot(x,fFS,'--')xlabel('x')ylabel('f(x)')title('Exercise 3-3 10 Modes with dx=0.01')

Page 17: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver:
Page 18: ME 565 Spring 2019 - HW 3, Problem 2 · ME 565 Spring 2019 - HW 3, Problem 2 AUTHOR : David Schipf, w/ some code from Professor Brunton DATE : Feb-2018 Revision : 1.00 MAT-LAB Ver: