Multiple Equations

조회 수: 8 (최근 30일)
Claire
Claire 2011년 1월 24일
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.
Thanks

채택된 답변

Sam G.
Sam G. 2011년 1월 24일
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.
  댓글 수: 3
Claire
Claire 2011년 1월 24일
Thanks Sam, much appreciated. Still fighting with my code, as it keeps giving the wrong answer, but at least it actually runs now.
Doug, can you explain what you mean by commenting in and uncommenting please? I'm really new to this, sorry.
Paulo Silva
Paulo Silva 2011년 2월 2일
%Dry = input('Dry bulb temperature (deg C): ');
Dry=1 %or other test value

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by