# Thread: Need Help with Function files and Fzero command (Homework problem MATLAB)

1. ## Need Help with Function files and Fzero command (Homework problem MATLAB)

Using estimates of rainfall, evaporation, etc. The town engineer developed the following model for the amount of water in the town reservoir as a function of time:

$V(t) = 10^9 + 10^8(1-e^{-t/100}) - rt$

where V is water volume in liters, t is time in days, and r is the towns consumption rate in liters per day. Write two user defined functions. The first function should define V(t) for use with the fzero function. The second function should use fzero to compute how long it will take for the water to decrease to $x$ percent of its initial value of $10^9$ L. The inputs of the second function should be $x$ and $r$.

to be totally honest I don't have the foggiest of an idea on where to start. I'm not looking for anyone to hand me the answer, I just want to be pointed in the right direction.

2. Is this assignment for a grade?

3. Originally Posted by Jenkins

Using estimates of rainfall, evaporation, etc. The town engineer developed the following model for the amount of water in the town reservoir as a function of time:

$V(t) = 10^9 + 10^8(1-e^{-t/100}) - rt$

where V is water volume in liters, t is time in days, and r is the towns consumption rate in liters per day. Write two user defined functions. The first function should define V(t) for use with the fzero function. The second function should use fzero to compute how long it will take for the water to decrease to $x$ percent of its initial value of $10^9$ L. The inputs of the second function should be $x$ and $r$.

to be totally honest I don't have the foggiest of an idea on where to start. I'm not looking for anyone to hand me the answer, I just want to be pointed in the right direction.
A basic function definition will look something like:

Code:
```function rv=FnName(x,y,z)
u=x+y;
rv=0;
if u>0
rv=x+y+z^2;
else
rv=7;
end```
The return value can be an array object, as can the arguments. The function needs to be placed in a .m file with the same name as the function on on the Matlab search path (IIRC the editor will offer to add the location to the search path when you save the file).

CB