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

  • Thread starter Thread starter George3
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion focuses on solving a MATLAB homework problem involving the function V(t), which models water volume in a reservoir. Users are tasked with creating two user-defined functions: one to define V(t) for use with MATLAB's fzero function, and another to compute the time for the water volume to reach a specified percentage of its initial value. A participant shares their attempts at coding these functions but struggles with obtaining the correct time for the volume decrease. Suggestions include reviewing MATLAB's fzero documentation and clarifying the relationship between the function outputs and the desired results. The conversation emphasizes the importance of correctly setting up the equations and ensuring proper input handling in the user-defined functions.
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 teh 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: ');

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

Vfinal = 10e9 *(xd/100)

diffV = VoT- 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?
 
Back
Top