SlideShare a Scribd company logo
1
Jared Fertig - ME 541 HW #4
Table of Contents
Problem 2 (dx = dy = .5) ..................................................................................................... 1
Problem 2 (dx = dy = .25) .................................................................................................... 5
Problem 2 (dx = dy = .5)
clear all
close all
clc
%set initial parameters
k = .05;
xmax = 10; % Maximum length (L)
ymax = 5; % Maximum height (H)
tmax = 100; % Maximum time (t)
dx = .5; %delta x
dy = .5; %delta y
dt = .1; %delta t
nx = xmax/dx;
ny = ymax/dy;
nt = tmax/dt;
x = 0:dx:xmax;
y = 0:dy:ymax;
t = 0:dt:tmax;
%coefficients
c = dt/(2*dx);
d = dt/(2*dy);
r = k*dt/(dx^2);
s = k*dt/(dy^2);
%Create velocity matrices
for ii = 1:length(x)
for jj = 1:length(y)
u(ii,jj) = .5*sin(2*pi()*x(ii)/xmax)*sin(pi()*y(jj)/ymax);
v(ii,jj) = 1*sin(2*pi()*x(ii)/xmax)*sin(pi()*y(jj)/ymax);
end
end
%Find maximum cell Reynolds Numbers
Jared Fertig - ME 541 HW #4
2
umax = max(max(u));
vmax = max(max(v));
Rcx = umax*dx/k;
disp(['The Maximum Reynolds Number in the x-direction is R_cx =',
num2str(Rcx)])
Rcy = vmax*dy/k;
disp(['The Maximum Reynolds Number in the y-direction is R_cy =',
num2str(Rcy)])
%Create the Temperature Matrix
T = zeros(nx+1,ny+1,nt+1);
%initial conditions
for ii = 1:nx+1
for kk = 2:nt+1
T(ii,1,kk) = 10*sin(pi()*x(ii)/xmax)^2;
T(ii,ny,kk) = 10*sin(pi()*x(ii)/xmax)^2;
end
end
for jj = 1:ny+1
for kk = 2:nt+1
T(1,jj,kk) = 5*sin(2*pi()*y(jj)/ymax)^2;
T(nx,jj,kk) = 5*sin(2*pi()*y(jj)/ymax)^2;
end
end
for ii = 1:nx+1
for jj = 1:ny+1
T(ii,jj,1) = 0;
end
end
%create matrix based on forward time center space
for kk = 1:nt
T(1,1,kk+1) = T(1,1,kk)-...
c*u(1,1)*(T(2,1,kk)-T(nx,1,kk))-...
c*v(1,1)*(T(1,2,kk)-T(1,ny,kk))+...
r*(T(2,1,kk)-2*T(1,1,kk)+T(nx,1,kk))+...
r*(T(1,ny,kk)-2*T(1,1,kk)+T(1,ny,kk));
for ii = 2:nx
for jj = 2:ny
T(ii,jj,kk+1)=T(ii,jj,kk)-...
c*u(ii,jj)*(T(ii+1,jj,kk)-T(ii-1,jj,kk))-...
c*v(ii,jj)*(T(ii,jj+1,kk)-T(ii,jj-1,kk))+...
r*(T(ii+1,jj,kk)-2*T(ii,jj,kk)+T(ii-1,jj,kk))+...
r*(T(ii,jj+1,kk)-2*T(ii,jj,kk)+T(ii,jj-1,kk));
end
for ll = 1:ny
T(nx+1,ll,kk+1)=T(1,ll,kk+1);
end
for mm = 1:nx
T(mm,ny+1,kk+1)=T(mm,1,kk+1);
Jared Fertig - ME 541 HW #4
3
end
end
end
%Calculate Temperature Matrix at the Center
T_center = T(nx/2,ny/2,:);
T_cent = T_center(:)';
figure(1)
plot(t,T_cent)
grid on
title('Temperature at Center vs Time')
xlabel('Time (s)')
ylabel('Temperature (deg)')
%Find Steady State Time and Temperature
tol = .0001;
pp = 40;
err = 1;
while err > tol
err = T_cent(pp+1) - T_cent(pp);
pp = pp + 1;
end
disp(['Steady State is Reached at the Center at ', num2str(t(pp)),'
seconds'])
disp(['The Steady State Temperature is ', num2str(T_cent(pp)),'
degrees'])
T_contour = T(:,:,pp);
C = rot90(T_contour);
figure(2)
contour(x,y,C,20);
title('Contour Plot at Steady State (20 Levels)')
xlabel('Distance')
ylabel('Height')
The Maximum Reynolds Number in the x-direction is R_cx =5
The Maximum Reynolds Number in the y-direction is R_cy =10
Steady State is Reached at the Center at 33.2 seconds
The Steady State Temperature is 7.1491 degrees
Jared Fertig - ME 541 HW #4
4
Jared Fertig - ME 541 HW #4
5
Problem 2 (dx = dy = .25)
%set initial parameters
k = .05;
xmax = 10; % Maximum length (L)
ymax = 5; % Maximum height (H)
tmax = 100; % Maximum time (t)
dx = .25; %delta x
dy = .25; %delta y
dt = .1; %delta t
nx = xmax/dx;
ny = ymax/dy;
nt = tmax/dt;
x = 0:dx:xmax;
y = 0:dy:ymax;
t = 0:dt:tmax;
%coefficients
c = dt/(2*dx);
d = dt/(2*dy);
r = k*dt/(dx^2);
s = k*dt/(dy^2);
%Create velocity matrices
for ii = 1:length(x)
for jj = 1:length(y)
u(ii,jj) = .5*sin(2*pi()*x(ii)/xmax)*sin(pi()*y(jj)/ymax);
v(ii,jj) = 1*sin(2*pi()*x(ii)/xmax)*sin(pi()*y(jj)/ymax);
end
end
%Find maximum cell Reynolds Numbers
umax = max(max(u));
vmax = max(max(v));
Rcx = umax*dx/k;
disp(['The Maximum Reynolds Number in the x-direction is R_cx =',
num2str(Rcx)])
Rcy = vmax*dy/k;
disp(['The Maximum Reynolds Number in the y-direction is R_cy =',
num2str(Rcy)])
%Create the Temperature Matrix
T = zeros(nx+1,ny+1,nt+1);
%initial conditions
for ii = 1:nx+1
for kk = 2:nt+1
Jared Fertig - ME 541 HW #4
6
T(ii,1,kk) = 10*sin(pi()*x(ii)/xmax)^2;
T(ii,ny,kk) = 10*sin(pi()*x(ii)/xmax)^2;
end
end
for jj = 1:ny+1
for kk = 2:nt+1
T(1,jj,kk) = 5*sin(2*pi()*y(jj)/ymax)^2;
T(nx,jj,kk) = 5*sin(2*pi()*y(jj)/ymax)^2;
end
end
for ii = 1:nx+1
for jj = 1:ny+1
T(ii,jj,1) = 0;
end
end
%create matrix based on forward time center space
for kk = 1:nt
T(1,1,kk+1) = T(1,1,kk)-...
c*u(1,1)*(T(2,1,kk)-T(nx,1,kk))-...
c*v(1,1)*(T(1,2,kk)-T(1,ny,kk))+...
r*(T(2,1,kk)-2*T(1,1,kk)+T(nx,1,kk))+...
r*(T(1,ny,kk)-2*T(1,1,kk)+T(1,ny,kk));
for ii = 2:nx
for jj = 2:ny
T(ii,jj,kk+1)=T(ii,jj,kk)-...
c*u(ii,jj)*(T(ii+1,jj,kk)-T(ii-1,jj,kk))-...
c*v(ii,jj)*(T(ii,jj+1,kk)-T(ii,jj-1,kk))+...
r*(T(ii+1,jj,kk)-2*T(ii,jj,kk)+T(ii-1,jj,kk))+...
r*(T(ii,jj+1,kk)-2*T(ii,jj,kk)+T(ii,jj-1,kk));
end
for ll = 1:ny
T(nx+1,ll,kk+1)=T(1,ll,kk+1);
end
for mm = 1:nx
T(mm,ny+1,kk+1)=T(mm,1,kk+1);
end
end
end
%Calculate Temperature Matrix at the Center
T_center = T(nx/2,ny/2,:);
T_cent = T_center(:)';
figure(3)
plot(t,T_cent)
grid on
title('Temperature at Center vs Time')
xlabel('Time (s)')
ylabel('Temperature (deg)')
%Find Steady State Time and Temperature
Jared Fertig - ME 541 HW #4
7
tol = .0001;
pp = 40;
err = 1;
while err > tol
err = T_cent(pp+1) - T_cent(pp);
pp = pp + 1;
end
disp(['Steady State is Reached at the Center at ', num2str(t(pp)),'
seconds'])
disp(['The Steady State Temperature is ', num2str(T_cent(pp)),'
degrees'])
T_contour = T(:,:,pp);
C = rot90(T_contour);
figure(4)
contour(x,y,C,20);
title('Contour Plot at Steady State (20 Levels)')
xlabel('Distance')
ylabel('Height')
The Maximum Reynolds Number in the x-direction is R_cx =2.5
The Maximum Reynolds Number in the y-direction is R_cy =5
Steady State is Reached at the Center at 34.5 seconds
The Steady State Temperature is 6.7535 degrees
Jared Fertig - ME 541 HW #4
8
Jared Fertig - ME 541 HW #4
9
Published with MATLAB® R2015b

More Related Content

What's hot

Csm chapters12
Csm chapters12Csm chapters12
Csm chapters12
Pamela Paz
 
Multiple Choice Questions on Frequency Response Analysis
Multiple Choice Questions on Frequency Response AnalysisMultiple Choice Questions on Frequency Response Analysis
Multiple Choice Questions on Frequency Response Analysis
VijayalaxmiKumbhar
 
Code chuyển từ lịch dương sang lịch âm
Code chuyển từ lịch dương sang lịch âmCode chuyển từ lịch dương sang lịch âm
Code chuyển từ lịch dương sang lịch âm
Freelancer
 
Testsol
TestsolTestsol
Testsol
Najmi Madzlan
 
Ma2002 1.9 rm
Ma2002 1.9 rmMa2002 1.9 rm
Ma2002 1.9 rm
Ramakrishna Paduchuri
 
communication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manualcommunication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manual
amirhosseinozgoli
 
Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715
HelpWithAssignment.com
 
Exercicios de integrais
Exercicios de integraisExercicios de integrais
Exercicios de integrais
Ribeij2
 
Ma2002 1.14 rm
Ma2002 1.14 rmMa2002 1.14 rm
Ma2002 1.14 rm
Ramakrishna Paduchuri
 
Communication systems solution manual 5th edition
Communication systems solution manual 5th editionCommunication systems solution manual 5th edition
Communication systems solution manual 5th edition
Tayeen Ahmed
 
Quadratic Expressions
Quadratic ExpressionsQuadratic Expressions
Quadratic Expressions
2IIM
 
Trigonometry 10th edition larson solutions manual
Trigonometry 10th edition larson solutions manualTrigonometry 10th edition larson solutions manual
Trigonometry 10th edition larson solutions manual
Larson2017
 
Manual solucoes ex_extras
Manual solucoes ex_extrasManual solucoes ex_extras
Manual solucoes ex_extras
Vandilberto Pinto
 
Bayes gauss
Bayes gaussBayes gauss
Summary Of Important Laws Of Differentiation And Integration
Summary Of Important Laws Of Differentiation And IntegrationSummary Of Important Laws Of Differentiation And Integration
Summary Of Important Laws Of Differentiation And Integration
Ahmed Hamed
 
Sol86
Sol86Sol86
On approximate bounds of zeros of polynomials within
On approximate bounds of zeros of polynomials withinOn approximate bounds of zeros of polynomials within
On approximate bounds of zeros of polynomials within
eSAT Publishing House
 
corripio
corripio corripio
corripio
Sabrina Amaral
 

What's hot (18)

Csm chapters12
Csm chapters12Csm chapters12
Csm chapters12
 
Multiple Choice Questions on Frequency Response Analysis
Multiple Choice Questions on Frequency Response AnalysisMultiple Choice Questions on Frequency Response Analysis
Multiple Choice Questions on Frequency Response Analysis
 
Code chuyển từ lịch dương sang lịch âm
Code chuyển từ lịch dương sang lịch âmCode chuyển từ lịch dương sang lịch âm
Code chuyển từ lịch dương sang lịch âm
 
Testsol
TestsolTestsol
Testsol
 
Ma2002 1.9 rm
Ma2002 1.9 rmMa2002 1.9 rm
Ma2002 1.9 rm
 
communication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manualcommunication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manual
 
Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715
 
Exercicios de integrais
Exercicios de integraisExercicios de integrais
Exercicios de integrais
 
Ma2002 1.14 rm
Ma2002 1.14 rmMa2002 1.14 rm
Ma2002 1.14 rm
 
Communication systems solution manual 5th edition
Communication systems solution manual 5th editionCommunication systems solution manual 5th edition
Communication systems solution manual 5th edition
 
Quadratic Expressions
Quadratic ExpressionsQuadratic Expressions
Quadratic Expressions
 
Trigonometry 10th edition larson solutions manual
Trigonometry 10th edition larson solutions manualTrigonometry 10th edition larson solutions manual
Trigonometry 10th edition larson solutions manual
 
Manual solucoes ex_extras
Manual solucoes ex_extrasManual solucoes ex_extras
Manual solucoes ex_extras
 
Bayes gauss
Bayes gaussBayes gauss
Bayes gauss
 
Summary Of Important Laws Of Differentiation And Integration
Summary Of Important Laws Of Differentiation And IntegrationSummary Of Important Laws Of Differentiation And Integration
Summary Of Important Laws Of Differentiation And Integration
 
Sol86
Sol86Sol86
Sol86
 
On approximate bounds of zeros of polynomials within
On approximate bounds of zeros of polynomials withinOn approximate bounds of zeros of polynomials within
On approximate bounds of zeros of polynomials within
 
corripio
corripio corripio
corripio
 

Viewers also liked

M1 unit vi-jntuworld
M1 unit vi-jntuworldM1 unit vi-jntuworld
M1 unit vi-jntuworld
mrecedu
 
AP Calculus BC: 10-06 Ratio and Root Test for Convergence of Series with all ...
AP Calculus BC: 10-06 Ratio and Root Test for Convergence of Series with all ...AP Calculus BC: 10-06 Ratio and Root Test for Convergence of Series with all ...
AP Calculus BC: 10-06 Ratio and Root Test for Convergence of Series with all ...
A Jorge Garcia
 
Mth3101 Advanced Calculus Chapter 3
Mth3101 Advanced Calculus Chapter 3Mth3101 Advanced Calculus Chapter 3
Mth3101 Advanced Calculus Chapter 3
saya efan
 
Turunan dan integral
Turunan dan integralTurunan dan integral
Turunan dan integral
Adi ansyah
 
Review of series
Review of seriesReview of series
Review of series
Tarun Gehlot
 
AP Calculus BC: 11-02 Generating Power Series!
AP Calculus BC: 11-02 Generating Power Series!AP Calculus BC: 11-02 Generating Power Series!
AP Calculus BC: 11-02 Generating Power Series!
A Jorge Garcia
 
GIG Corporate Kit 2015
GIG Corporate Kit 2015GIG Corporate Kit 2015
GIG Corporate Kit 2015
Nesan Naidoo MBA
 
Días y Hechos de la Semana Santa
Días y Hechos de la Semana SantaDías y Hechos de la Semana Santa
Días y Hechos de la Semana Santa
kamiloncha
 
PM Valencia Orange v010117
PM Valencia Orange v010117PM Valencia Orange v010117
PM Valencia Orange v010117
Productores Mexicanos
 
Agricultores Familiares 2017
Agricultores Familiares 2017Agricultores Familiares 2017
Agricultores Familiares 2017
Productores Mexicanos
 
Dhanasekar Resume update on OCT 11
Dhanasekar Resume update on OCT 11Dhanasekar Resume update on OCT 11
Dhanasekar Resume update on OCT 11
DHANASEKAR M
 
Grammar2
Grammar2Grammar2
Grammar2
Google
 
Calculus 11 sequences_and_series
Calculus 11 sequences_and_seriesCalculus 11 sequences_and_series
Calculus 11 sequences_and_series
Abner Kalaputse Shifula
 
Calculus II - 24
Calculus II - 24Calculus II - 24
Calculus II - 24
David Mao
 
Portfolio matteo ceddia
Portfolio matteo ceddiaPortfolio matteo ceddia
Portfolio matteo ceddia
Matteo Ceddia
 
Электронная подпись в LanDocs
Электронная подпись в LanDocsЭлектронная подпись в LanDocs
Электронная подпись в LanDocs
LANIT
 
power series & radius of convergence
power series & radius of convergencepower series & radius of convergence
power series & radius of convergence
jigar sable
 
Dynamic light scattering
Dynamic light scatteringDynamic light scattering
Dynamic light scattering
MannuMaken92
 
Mesoporous material
Mesoporous materialMesoporous material
Mesoporous material
MannuMaken92
 
試してわかるSDN
試してわかるSDN試してわかるSDN
試してわかるSDN
cloretsblack
 

Viewers also liked (20)

M1 unit vi-jntuworld
M1 unit vi-jntuworldM1 unit vi-jntuworld
M1 unit vi-jntuworld
 
AP Calculus BC: 10-06 Ratio and Root Test for Convergence of Series with all ...
AP Calculus BC: 10-06 Ratio and Root Test for Convergence of Series with all ...AP Calculus BC: 10-06 Ratio and Root Test for Convergence of Series with all ...
AP Calculus BC: 10-06 Ratio and Root Test for Convergence of Series with all ...
 
Mth3101 Advanced Calculus Chapter 3
Mth3101 Advanced Calculus Chapter 3Mth3101 Advanced Calculus Chapter 3
Mth3101 Advanced Calculus Chapter 3
 
Turunan dan integral
Turunan dan integralTurunan dan integral
Turunan dan integral
 
Review of series
Review of seriesReview of series
Review of series
 
AP Calculus BC: 11-02 Generating Power Series!
AP Calculus BC: 11-02 Generating Power Series!AP Calculus BC: 11-02 Generating Power Series!
AP Calculus BC: 11-02 Generating Power Series!
 
GIG Corporate Kit 2015
GIG Corporate Kit 2015GIG Corporate Kit 2015
GIG Corporate Kit 2015
 
Días y Hechos de la Semana Santa
Días y Hechos de la Semana SantaDías y Hechos de la Semana Santa
Días y Hechos de la Semana Santa
 
PM Valencia Orange v010117
PM Valencia Orange v010117PM Valencia Orange v010117
PM Valencia Orange v010117
 
Agricultores Familiares 2017
Agricultores Familiares 2017Agricultores Familiares 2017
Agricultores Familiares 2017
 
Dhanasekar Resume update on OCT 11
Dhanasekar Resume update on OCT 11Dhanasekar Resume update on OCT 11
Dhanasekar Resume update on OCT 11
 
Grammar2
Grammar2Grammar2
Grammar2
 
Calculus 11 sequences_and_series
Calculus 11 sequences_and_seriesCalculus 11 sequences_and_series
Calculus 11 sequences_and_series
 
Calculus II - 24
Calculus II - 24Calculus II - 24
Calculus II - 24
 
Portfolio matteo ceddia
Portfolio matteo ceddiaPortfolio matteo ceddia
Portfolio matteo ceddia
 
Электронная подпись в LanDocs
Электронная подпись в LanDocsЭлектронная подпись в LanDocs
Электронная подпись в LanDocs
 
power series & radius of convergence
power series & radius of convergencepower series & radius of convergence
power series & radius of convergence
 
Dynamic light scattering
Dynamic light scatteringDynamic light scattering
Dynamic light scattering
 
Mesoporous material
Mesoporous materialMesoporous material
Mesoporous material
 
試してわかるSDN
試してわかるSDN試してわかるSDN
試してわかるSDN
 

Similar to ME_541_HW_04

Heat Map Modeling Using Resistive Network
Heat Map Modeling Using Resistive NetworkHeat Map Modeling Using Resistive Network
Heat Map Modeling Using Resistive Network
ssurgnier
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
GadaFarhan
 
DSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxDSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docx
MUMAR57
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
Amr Rashed
 
IVR - Chapter 4 - Variational methods
IVR - Chapter 4 - Variational methodsIVR - Chapter 4 - Variational methods
IVR - Chapter 4 - Variational methods
Charles Deledalle
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
ATT00001ATT00002ATT00003ATT00004ATT00005CARD.docx
ATT00001ATT00002ATT00003ATT00004ATT00005CARD.docxATT00001ATT00002ATT00003ATT00004ATT00005CARD.docx
ATT00001ATT00002ATT00003ATT00004ATT00005CARD.docx
ikirkton
 
Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...
Alexander Litvinenko
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
subhashchandra197
 
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Alexander Litvinenko
 
Dsp iit workshop
Dsp iit workshopDsp iit workshop
Laplace_1.ppt
Laplace_1.pptLaplace_1.ppt
Laplace_1.ppt
cantatebrugyral
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
matlab codes.pdf
matlab codes.pdfmatlab codes.pdf
matlab codes.pdf
EdysaulCondorhuancar
 
Automatic Control Via Thermostats Of A Hyperbolic Stefan Problem With Memory
Automatic Control Via Thermostats Of A Hyperbolic Stefan Problem With MemoryAutomatic Control Via Thermostats Of A Hyperbolic Stefan Problem With Memory
Automatic Control Via Thermostats Of A Hyperbolic Stefan Problem With Memory
Crystal Sanchez
 
LINEAR SYSTEMS
LINEAR SYSTEMSLINEAR SYSTEMS
LINEAR SYSTEMS
JazzieJao1
 
Contemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manualContemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manual
to2001
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
Megha V
 
Remark on variance swaps pricing
Remark on variance swaps pricingRemark on variance swaps pricing
Remark on variance swaps pricing
Ilya Gikhman
 

Similar to ME_541_HW_04 (20)

Heat Map Modeling Using Resistive Network
Heat Map Modeling Using Resistive NetworkHeat Map Modeling Using Resistive Network
Heat Map Modeling Using Resistive Network
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
 
DSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxDSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docx
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
IVR - Chapter 4 - Variational methods
IVR - Chapter 4 - Variational methodsIVR - Chapter 4 - Variational methods
IVR - Chapter 4 - Variational methods
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
ATT00001ATT00002ATT00003ATT00004ATT00005CARD.docx
ATT00001ATT00002ATT00003ATT00004ATT00005CARD.docxATT00001ATT00002ATT00003ATT00004ATT00005CARD.docx
ATT00001ATT00002ATT00003ATT00004ATT00005CARD.docx
 
Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
 
Dsp iit workshop
Dsp iit workshopDsp iit workshop
Dsp iit workshop
 
Laplace_1.ppt
Laplace_1.pptLaplace_1.ppt
Laplace_1.ppt
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
matlab codes.pdf
matlab codes.pdfmatlab codes.pdf
matlab codes.pdf
 
Automatic Control Via Thermostats Of A Hyperbolic Stefan Problem With Memory
Automatic Control Via Thermostats Of A Hyperbolic Stefan Problem With MemoryAutomatic Control Via Thermostats Of A Hyperbolic Stefan Problem With Memory
Automatic Control Via Thermostats Of A Hyperbolic Stefan Problem With Memory
 
LINEAR SYSTEMS
LINEAR SYSTEMSLINEAR SYSTEMS
LINEAR SYSTEMS
 
Contemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manualContemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manual
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Remark on variance swaps pricing
Remark on variance swaps pricingRemark on variance swaps pricing
Remark on variance swaps pricing
 

ME_541_HW_04

  • 1. 1 Jared Fertig - ME 541 HW #4 Table of Contents Problem 2 (dx = dy = .5) ..................................................................................................... 1 Problem 2 (dx = dy = .25) .................................................................................................... 5 Problem 2 (dx = dy = .5) clear all close all clc %set initial parameters k = .05; xmax = 10; % Maximum length (L) ymax = 5; % Maximum height (H) tmax = 100; % Maximum time (t) dx = .5; %delta x dy = .5; %delta y dt = .1; %delta t nx = xmax/dx; ny = ymax/dy; nt = tmax/dt; x = 0:dx:xmax; y = 0:dy:ymax; t = 0:dt:tmax; %coefficients c = dt/(2*dx); d = dt/(2*dy); r = k*dt/(dx^2); s = k*dt/(dy^2); %Create velocity matrices for ii = 1:length(x) for jj = 1:length(y) u(ii,jj) = .5*sin(2*pi()*x(ii)/xmax)*sin(pi()*y(jj)/ymax); v(ii,jj) = 1*sin(2*pi()*x(ii)/xmax)*sin(pi()*y(jj)/ymax); end end %Find maximum cell Reynolds Numbers
  • 2. Jared Fertig - ME 541 HW #4 2 umax = max(max(u)); vmax = max(max(v)); Rcx = umax*dx/k; disp(['The Maximum Reynolds Number in the x-direction is R_cx =', num2str(Rcx)]) Rcy = vmax*dy/k; disp(['The Maximum Reynolds Number in the y-direction is R_cy =', num2str(Rcy)]) %Create the Temperature Matrix T = zeros(nx+1,ny+1,nt+1); %initial conditions for ii = 1:nx+1 for kk = 2:nt+1 T(ii,1,kk) = 10*sin(pi()*x(ii)/xmax)^2; T(ii,ny,kk) = 10*sin(pi()*x(ii)/xmax)^2; end end for jj = 1:ny+1 for kk = 2:nt+1 T(1,jj,kk) = 5*sin(2*pi()*y(jj)/ymax)^2; T(nx,jj,kk) = 5*sin(2*pi()*y(jj)/ymax)^2; end end for ii = 1:nx+1 for jj = 1:ny+1 T(ii,jj,1) = 0; end end %create matrix based on forward time center space for kk = 1:nt T(1,1,kk+1) = T(1,1,kk)-... c*u(1,1)*(T(2,1,kk)-T(nx,1,kk))-... c*v(1,1)*(T(1,2,kk)-T(1,ny,kk))+... r*(T(2,1,kk)-2*T(1,1,kk)+T(nx,1,kk))+... r*(T(1,ny,kk)-2*T(1,1,kk)+T(1,ny,kk)); for ii = 2:nx for jj = 2:ny T(ii,jj,kk+1)=T(ii,jj,kk)-... c*u(ii,jj)*(T(ii+1,jj,kk)-T(ii-1,jj,kk))-... c*v(ii,jj)*(T(ii,jj+1,kk)-T(ii,jj-1,kk))+... r*(T(ii+1,jj,kk)-2*T(ii,jj,kk)+T(ii-1,jj,kk))+... r*(T(ii,jj+1,kk)-2*T(ii,jj,kk)+T(ii,jj-1,kk)); end for ll = 1:ny T(nx+1,ll,kk+1)=T(1,ll,kk+1); end for mm = 1:nx T(mm,ny+1,kk+1)=T(mm,1,kk+1);
  • 3. Jared Fertig - ME 541 HW #4 3 end end end %Calculate Temperature Matrix at the Center T_center = T(nx/2,ny/2,:); T_cent = T_center(:)'; figure(1) plot(t,T_cent) grid on title('Temperature at Center vs Time') xlabel('Time (s)') ylabel('Temperature (deg)') %Find Steady State Time and Temperature tol = .0001; pp = 40; err = 1; while err > tol err = T_cent(pp+1) - T_cent(pp); pp = pp + 1; end disp(['Steady State is Reached at the Center at ', num2str(t(pp)),' seconds']) disp(['The Steady State Temperature is ', num2str(T_cent(pp)),' degrees']) T_contour = T(:,:,pp); C = rot90(T_contour); figure(2) contour(x,y,C,20); title('Contour Plot at Steady State (20 Levels)') xlabel('Distance') ylabel('Height') The Maximum Reynolds Number in the x-direction is R_cx =5 The Maximum Reynolds Number in the y-direction is R_cy =10 Steady State is Reached at the Center at 33.2 seconds The Steady State Temperature is 7.1491 degrees
  • 4. Jared Fertig - ME 541 HW #4 4
  • 5. Jared Fertig - ME 541 HW #4 5 Problem 2 (dx = dy = .25) %set initial parameters k = .05; xmax = 10; % Maximum length (L) ymax = 5; % Maximum height (H) tmax = 100; % Maximum time (t) dx = .25; %delta x dy = .25; %delta y dt = .1; %delta t nx = xmax/dx; ny = ymax/dy; nt = tmax/dt; x = 0:dx:xmax; y = 0:dy:ymax; t = 0:dt:tmax; %coefficients c = dt/(2*dx); d = dt/(2*dy); r = k*dt/(dx^2); s = k*dt/(dy^2); %Create velocity matrices for ii = 1:length(x) for jj = 1:length(y) u(ii,jj) = .5*sin(2*pi()*x(ii)/xmax)*sin(pi()*y(jj)/ymax); v(ii,jj) = 1*sin(2*pi()*x(ii)/xmax)*sin(pi()*y(jj)/ymax); end end %Find maximum cell Reynolds Numbers umax = max(max(u)); vmax = max(max(v)); Rcx = umax*dx/k; disp(['The Maximum Reynolds Number in the x-direction is R_cx =', num2str(Rcx)]) Rcy = vmax*dy/k; disp(['The Maximum Reynolds Number in the y-direction is R_cy =', num2str(Rcy)]) %Create the Temperature Matrix T = zeros(nx+1,ny+1,nt+1); %initial conditions for ii = 1:nx+1 for kk = 2:nt+1
  • 6. Jared Fertig - ME 541 HW #4 6 T(ii,1,kk) = 10*sin(pi()*x(ii)/xmax)^2; T(ii,ny,kk) = 10*sin(pi()*x(ii)/xmax)^2; end end for jj = 1:ny+1 for kk = 2:nt+1 T(1,jj,kk) = 5*sin(2*pi()*y(jj)/ymax)^2; T(nx,jj,kk) = 5*sin(2*pi()*y(jj)/ymax)^2; end end for ii = 1:nx+1 for jj = 1:ny+1 T(ii,jj,1) = 0; end end %create matrix based on forward time center space for kk = 1:nt T(1,1,kk+1) = T(1,1,kk)-... c*u(1,1)*(T(2,1,kk)-T(nx,1,kk))-... c*v(1,1)*(T(1,2,kk)-T(1,ny,kk))+... r*(T(2,1,kk)-2*T(1,1,kk)+T(nx,1,kk))+... r*(T(1,ny,kk)-2*T(1,1,kk)+T(1,ny,kk)); for ii = 2:nx for jj = 2:ny T(ii,jj,kk+1)=T(ii,jj,kk)-... c*u(ii,jj)*(T(ii+1,jj,kk)-T(ii-1,jj,kk))-... c*v(ii,jj)*(T(ii,jj+1,kk)-T(ii,jj-1,kk))+... r*(T(ii+1,jj,kk)-2*T(ii,jj,kk)+T(ii-1,jj,kk))+... r*(T(ii,jj+1,kk)-2*T(ii,jj,kk)+T(ii,jj-1,kk)); end for ll = 1:ny T(nx+1,ll,kk+1)=T(1,ll,kk+1); end for mm = 1:nx T(mm,ny+1,kk+1)=T(mm,1,kk+1); end end end %Calculate Temperature Matrix at the Center T_center = T(nx/2,ny/2,:); T_cent = T_center(:)'; figure(3) plot(t,T_cent) grid on title('Temperature at Center vs Time') xlabel('Time (s)') ylabel('Temperature (deg)') %Find Steady State Time and Temperature
  • 7. Jared Fertig - ME 541 HW #4 7 tol = .0001; pp = 40; err = 1; while err > tol err = T_cent(pp+1) - T_cent(pp); pp = pp + 1; end disp(['Steady State is Reached at the Center at ', num2str(t(pp)),' seconds']) disp(['The Steady State Temperature is ', num2str(T_cent(pp)),' degrees']) T_contour = T(:,:,pp); C = rot90(T_contour); figure(4) contour(x,y,C,20); title('Contour Plot at Steady State (20 Levels)') xlabel('Distance') ylabel('Height') The Maximum Reynolds Number in the x-direction is R_cx =2.5 The Maximum Reynolds Number in the y-direction is R_cy =5 Steady State is Reached at the Center at 34.5 seconds The Steady State Temperature is 6.7535 degrees
  • 8. Jared Fertig - ME 541 HW #4 8
  • 9. Jared Fertig - ME 541 HW #4 9 Published with MATLAB® R2015b