SlideShare a Scribd company logo
11/18/16 12:55 PM C:UsersAlexi...MATLAB_Final_Project.m 1 of 2
%Final Project
%Ratio Funtion File (Mixing_Ratio.m) for Delta_q Funtion File
function [w] = Mixing_Ratio(T_a, p_a)
%Mixing Ratio calculates the ratio of the mass of water vapor to the mass of dry air at
the points temperature T_a and pressure p_a.
%All variables listed below were provided
p_ref=1013.246; %Normal atmospheric pressure ~1atm
T_ref=373.15; %The boiling point of water in Kelvin
e_1=11.344*(1-(T_a/T_ref));
e_2=-3.49149*((T_ref/T_a)-1);
f_1=-7.90298*((T_ref/T_a)-1);
f_2=5.02808*log10(T_ref/T_a);
f_3=(-1.3816*(10^(e_1)-1))*10^-7;
f_4=(8.1328*(10^(e_2)-1))*10^-3;
f_5=log10(p_ref);
f=f_1+f_2+f_3+f_4+f_5;
e=10^f;
w=(0.62197*e)/((p_a)-e); %The equation for calculating the mixing ratio
end
%Temperture Computation Function File (Delta_q.m) using Mixing_Ratio.m
function [Temp] = Delta_q(T)
%Delta_q computes the temperature based on the function file Mixing_Ratio and defines
global parameters to be used in the calculation of the script file Wet_Bulb.
global T_a T_d p_a
c_p=1005; %given value
L=2.501*10^6; %given value
Temp=[((L*(Mixing_Ratio(T, p_a)-Mixing_Ratio(T_d, p_a)))/(1+Mixing_Ratio(T, p_a)))-(c_p*
(T_a-T)*(1+0.8*Mixing_Ratio(T, p_a)))];
end
%Funtion File (f.m) for Root_Finder.m
function [ y ] = f( x )
%f defines the provided function to test the Root_Finder function file. This function
needs to be used as a input in the form of "@f" in the Root_Finder input arguments
%Root_Finder(@f, 0, 2) to test this function in the Root_Finder function file.
y = x^2 - 2;
end
%Root Finding Program used for Wet Bulb Program
function [x] = Root_Finder(f, a, b)
% Finds approximate roots within an absolute error of 10^-3, when you provide the
function with the inputs of:
%f(x): the continuous function in which roots need to be approximated
11/18/16 12:55 PM C:UsersAlexi...MATLAB_Final_Project.m 2 of 2
%[a,b]: the interval at which the function should be approximated
% then produces a single output containing the value of the approximation, x.
%To test run Root_Finder(@f, 0, 2)
c=f(a); %evaluates at the lower boundary of the interval to determine sign
d=f(b); %evaluates at the upper boundary of the interval to determine sign
if c*d>0 %Checks to see if the signs are opposite; if not displays error.
x=NaN;
else
e=1;
while e>10^-3 %defines the number of iterations that it will bisect the interval [a.b] to
approximate the root
x=(a+b)/2; %equation for bisecting the interval
y=f(x);
if c*y<0 %determines which end of the [a,b] interval needs to be bisected
b=x;
else
a=x;
end
e=(b-a)/2;
end
x=(a+b)/2;
end
end
%Program that computes the temperature based on Temperature, Dew Point, and
%Atomospheric Pressure
%%
% $x^2+e^{pi i}$ %Wet_Bulb uses the Root_Finder and Delta_q functions to compute the
temperature of wetbulb based on the globally defined parameters atmospheric temperature
T_a, dew point temperature T_d, and atmospheric pressure p_a
global T_a T_d p_a
Ta=input('Enter the current air temperature in degrees Farenheit: n');
Td=input('Enter the current dew point: n');
p_a=input('Enter the current atmospheric pressure in Hectopascals: n');
T_a=(Ta+459.67)*5/9;
T_d=(Td+459.67)*5/9;
Temperature=Root_Finder(@Delta_q, T_d, T_a) %calls the Delta_q

More Related Content

PDF
C language flowcharat
PDF
PPT
Removal Of Recursion
PPTX
Tail Recursion in data structure
PDF
ICP - Lecture 5
PDF
State-Space Realizations Using Control Canonical Form and Simulation Diagram
PDF
Provided MATLAB functions, convert the State Space Model into a classical con...
PPTX
Ch4.mapreduce algorithm design
C language flowcharat
Removal Of Recursion
Tail Recursion in data structure
ICP - Lecture 5
State-Space Realizations Using Control Canonical Form and Simulation Diagram
Provided MATLAB functions, convert the State Space Model into a classical con...
Ch4.mapreduce algorithm design

What's hot (20)

PPTX
parallelizing Trapezoidal rule
PPTX
9. 8085 instruction set v
PDF
13. quadratic formtemplatetouchpad
PPSX
Software Metrics
PDF
Gilbert: Declarative Sparse Linear Algebra on Massively Parallel Dataflow Sys...
PDF
Derivatives 11 25 08
PPTX
4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...
PPTX
Loop control structure
PDF
Matlab functions
PPTX
c++ programming Unit 1 introduction to c++
PDF
array, function, pointer, pattern matching
PDF
Filter Designing
PPTX
observer based state feedback controller design in Matlab (Simulink).
PPT
Me330 lecture2
PPTX
Adbms 39 algorithms for project and set operations
DOCX
Computer Architecture and Organization lab with matlab
PDF
Programming in lua Basic
PPT
Lecture#5 Operators in C++
PPTX
Block diagram representation 3
parallelizing Trapezoidal rule
9. 8085 instruction set v
13. quadratic formtemplatetouchpad
Software Metrics
Gilbert: Declarative Sparse Linear Algebra on Massively Parallel Dataflow Sys...
Derivatives 11 25 08
4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...
Loop control structure
Matlab functions
c++ programming Unit 1 introduction to c++
array, function, pointer, pattern matching
Filter Designing
observer based state feedback controller design in Matlab (Simulink).
Me330 lecture2
Adbms 39 algorithms for project and set operations
Computer Architecture and Organization lab with matlab
Programming in lua Basic
Lecture#5 Operators in C++
Block diagram representation 3
Ad

Viewers also liked (12)

DOCX
Vitamin D for Disaster Response - summary
PDF
Kalashnikov o a_-_assembler__eto_prosto_uchi
PDF
UROP MPC Report
PPTX
PPTX
Asbestos to banned
PPTX
A2 Media - Storyboard for trailer
PDF
Thyna Petroleum Services
DOC
PLAN DE ÁREA, HUMANIDADES LENGUA EXTRANJERA, INGLÉS, IECL, 2016
PPTX
PPT
Tanda Baca / Punctuations for P5
PPTX
Romance de Rita R
PPTX
penjodoh bilangan tahun 3
Vitamin D for Disaster Response - summary
Kalashnikov o a_-_assembler__eto_prosto_uchi
UROP MPC Report
Asbestos to banned
A2 Media - Storyboard for trailer
Thyna Petroleum Services
PLAN DE ÁREA, HUMANIDADES LENGUA EXTRANJERA, INGLÉS, IECL, 2016
Tanda Baca / Punctuations for P5
Romance de Rita R
penjodoh bilangan tahun 3
Ad

More from Alexis Ploss (6)

PDF
Pop Quiz.nb (1)
PDF
Cooling Project for Students- Answer Key
PDF
Cooling Project Data
PDF
Cooling Project Experiment
PDF
Final Project
PDF
Project 1
Pop Quiz.nb (1)
Cooling Project for Students- Answer Key
Cooling Project Data
Cooling Project Experiment
Final Project
Project 1

MATLAB Final Project

  • 1. 11/18/16 12:55 PM C:UsersAlexi...MATLAB_Final_Project.m 1 of 2 %Final Project %Ratio Funtion File (Mixing_Ratio.m) for Delta_q Funtion File function [w] = Mixing_Ratio(T_a, p_a) %Mixing Ratio calculates the ratio of the mass of water vapor to the mass of dry air at the points temperature T_a and pressure p_a. %All variables listed below were provided p_ref=1013.246; %Normal atmospheric pressure ~1atm T_ref=373.15; %The boiling point of water in Kelvin e_1=11.344*(1-(T_a/T_ref)); e_2=-3.49149*((T_ref/T_a)-1); f_1=-7.90298*((T_ref/T_a)-1); f_2=5.02808*log10(T_ref/T_a); f_3=(-1.3816*(10^(e_1)-1))*10^-7; f_4=(8.1328*(10^(e_2)-1))*10^-3; f_5=log10(p_ref); f=f_1+f_2+f_3+f_4+f_5; e=10^f; w=(0.62197*e)/((p_a)-e); %The equation for calculating the mixing ratio end %Temperture Computation Function File (Delta_q.m) using Mixing_Ratio.m function [Temp] = Delta_q(T) %Delta_q computes the temperature based on the function file Mixing_Ratio and defines global parameters to be used in the calculation of the script file Wet_Bulb. global T_a T_d p_a c_p=1005; %given value L=2.501*10^6; %given value Temp=[((L*(Mixing_Ratio(T, p_a)-Mixing_Ratio(T_d, p_a)))/(1+Mixing_Ratio(T, p_a)))-(c_p* (T_a-T)*(1+0.8*Mixing_Ratio(T, p_a)))]; end %Funtion File (f.m) for Root_Finder.m function [ y ] = f( x ) %f defines the provided function to test the Root_Finder function file. This function needs to be used as a input in the form of "@f" in the Root_Finder input arguments %Root_Finder(@f, 0, 2) to test this function in the Root_Finder function file. y = x^2 - 2; end %Root Finding Program used for Wet Bulb Program function [x] = Root_Finder(f, a, b) % Finds approximate roots within an absolute error of 10^-3, when you provide the function with the inputs of: %f(x): the continuous function in which roots need to be approximated
  • 2. 11/18/16 12:55 PM C:UsersAlexi...MATLAB_Final_Project.m 2 of 2 %[a,b]: the interval at which the function should be approximated % then produces a single output containing the value of the approximation, x. %To test run Root_Finder(@f, 0, 2) c=f(a); %evaluates at the lower boundary of the interval to determine sign d=f(b); %evaluates at the upper boundary of the interval to determine sign if c*d>0 %Checks to see if the signs are opposite; if not displays error. x=NaN; else e=1; while e>10^-3 %defines the number of iterations that it will bisect the interval [a.b] to approximate the root x=(a+b)/2; %equation for bisecting the interval y=f(x); if c*y<0 %determines which end of the [a,b] interval needs to be bisected b=x; else a=x; end e=(b-a)/2; end x=(a+b)/2; end end %Program that computes the temperature based on Temperature, Dew Point, and %Atomospheric Pressure %% % $x^2+e^{pi i}$ %Wet_Bulb uses the Root_Finder and Delta_q functions to compute the temperature of wetbulb based on the globally defined parameters atmospheric temperature T_a, dew point temperature T_d, and atmospheric pressure p_a global T_a T_d p_a Ta=input('Enter the current air temperature in degrees Farenheit: n'); Td=input('Enter the current dew point: n'); p_a=input('Enter the current atmospheric pressure in Hectopascals: n'); T_a=(Ta+459.67)*5/9; T_d=(Td+459.67)*5/9; Temperature=Root_Finder(@Delta_q, T_d, T_a) %calls the Delta_q