Multiple Equations

5 views (last 30 days)
Claire on 24 Jan 2011
Hi, I'm really rather new to Matlab, and totally confused. I'm trying to write some equations for evapotranspiration, and I'm rather stuck. I've got my constants and my equations written as below:
gs = 0.108; %stomatal conductance m^-1%
ga = 0.002; %atmospheric conductance m^-1%
G = 0; %soil heat flux W m^-2)%
rho = 1.22; %density of air Kg m^-3%
cp = 1006; %specific heat of air J Kg^-1 degrees C^-1%
gamma = 0.655; %psychrometric constant%
pw = 998; %density of water KG m^-3%
lambda = 2495000; %latent heat for vapourisation J/kg%
Dry = -100 : 100; %Dry Bulb temperature degree C%
sat = 0.611 * exp ((17.27 * Dry)/... %Saturated vapour pressure KPa%
237.3 + Dry);
delta = 4098 * sat / ...%slope of vapour pressure curve at air temperature%
(237.3 + Dry)*(237.3 + Dry);
Rs = 0 : 40000; %Incoming Radiation W m^-2%
Wet = -100 : 100; %Wet Bulb temperature degree C%
Rn = -18.308 + 0.681 * Rs; %Net radiation W M^2%
Unsat = 0.611 * exp ((17.27 * Wet) /... %Unsaturated vapour pressure KPa%
(237.3 + Wet));
Vap = Dry - Wet; % Vapour Pressure Deficit KPa%
Soil = Rn * 0.2; % Soil heat flux%
E= (delta * (Rn - Soil) + (rho * cp * Vap * ga)...
/ (delta + lambda * (1 +(ga/gs))))
Hours = 1:1:23; % Hours in a day%
Secs = Hours * 3600; %seconds in an hour%
Evap = (E/ (lambda * pw)) * 1000 * Secs %Evapotranspiration (mm per day)
My problem however is now that I want to be able to enter my 4 variables, Dry, Rs, Wet and Hours, and solve the equations, but I don't really know how to do it.
I eventually hope to make it into a GUI but I'm just trying to take it one step at a time. Any pointers would be much welcome.

Accepted Answer

Sam G.
Sam G. on 24 Jan 2011
If you want to enter the variables in the command window, you can use the input command. For example, to prompt the user for the value of Dry you would use the line of code
Dry = input('Dry bulb temperature (deg C): ');
Then whenever you run the m-file you will be prompted for the values of each variable. If you want a more efficient (but less descriptive) approach, you could define your m-file as a function of the four variables that you mention. You would put the following in the first line of the m-file.
function Evap = funName(Dry, Rs, Wet, Hours)
Assuming Evap is the result you are interested in. Then, in the command window, you would enter
funName(50, 30, 80, 10)
to evaluate the function. You could also call the function in a GUI if you make one in the future.
Paulo Silva
Paulo Silva on 2 Feb 2011
%Dry = input('Dry bulb temperature (deg C): ');
Dry=1 %or other test value

Sign in to comment.

More Answers (0)


Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!