MATLAB FZERO Help: Solving Homework Equations with User-Defined Functions

  • Thread starter Thread starter George3
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 10K views
George3
Messages
31
Reaction score
0

Homework Statement


Using estimates of rainfall,evaporation, and water consumption, the town engineer developed the following model of water volume in the reservoir as a function of time:

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

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



Homework Equations





The Attempt at a Solution


Im not really sure how to tackle this problem> I went to the MATLAB help and did their examples on fzero but this just seems to be a lot different. Thanks
 
Physics news on Phys.org
Part A:

Check out example 3 on http://www.mathworks.com/access/helpdesk_r13/help/techdoc/ref/fzero.html

You are supposed to write "f.m" for this problem.

Part B:

The MATLAB function fzero finds zero points for a function with a single variable. One could imagine:

[1] V/V0 = f(x)

where V is the volume, and V0 is the initial volume. If V = V0, then you have 100% of the original volume. Rearranging:

[2] f(x) - V/V0 = 0

What will the roots of the LHS of [2] represent?
 


For my code of the first function i havecome up with :
function diffV = deltaV(t);
%UNTITLED Summary of this function goes here
% Detailed explanation goes here

global rd xd


rd = input('Enter a rate of water consumption: ');
xd = input( 'Enter a percent of initial volume: ');

volt = 10e9 + 10e8*(1 -exp(-t./100)) - (rd).*t

Vfinal = 10e9 *(xd/100)

diffV = volt- Vfinal
end

And for my second function piece of code I have come up with :

function t_dec = time_todecrease(xd ,rd)
global xd rd

t_dec = fzero('deltaV',10)
xd
rd

end

This sort of works but does not give me the time it took to decrease. Any ideas with what's wrong with my code?