MATLAB
Using predicted values of rainfall, evaporation and water
consumption, the urban engineer developed a model for the amount of
water in the reservoir as a function of time as follows.
V(t)= 10^9 + 10^8 (1-e^(-t/100))-rt
where V is the amount of water represented by the litre, t is the
time of day, r is the daily consumption rate of the city expressed
by the litre/day. Create two user-defined functions. The first
function uses the fzero function to define the usage function V(t).
In the second function, the fzero function is used to calculate how
long it takes to reduce the initial value of 10L(9)L by x percent.
The inputs for the second function are x and r. Check the function
for x=50 percent and r= 10^(7)L/day.
Given : V(t)= 10^9 + 10^8 (1-e^(-t/100))-rt
Where ,V is the amount of water represented by the litre
t is the time of day
r is the daily consumption rate of the city expressed by the litre/day.
Code:
function t=watervolume(x,r)
V=@ (t) 10^9 + 10^8 * (1-exp (-t/100) ) - r * t ;
fun = @ (T) V(t) /10^9 * 100 - x;
t = fzero (fun , [0,150]);
end
Explanation : first function is private
In the second function fun we calculates root of non-linear function.
The inputs are gievn as
> x = 50;
> r=10^7;
> watervolume(x , r)
Output:54.183
Get Answers For Free
Most questions answered within 1 hours.