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

  • Thread starter George3
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses a model created by the town engineer to predict water volume in a reservoir based on rainfall, evaporation, and water consumption. Two user-defined functions are required: one to define the volume function for use with the fzero function, and another to use fzero to calculate the time it takes for the volume to decrease to a certain percentage of its initial value. The first function uses the inputs of time, water consumption rate, and percent of initial volume, while the second function uses the inputs of percent of initial volume and water consumption rate. The code provided by the speaker is incorrect and needs to be revised.
  • #1
George3
31
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
  • #2
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?
 
  • #3


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?
 

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

What is MATLAB FZERO?

MATLAB FZERO is a function in the MATLAB software that helps solve equations numerically using a user-defined function. It is commonly used in scientific and mathematical computations.

How does FZERO work?

FZERO uses a combination of algorithms and techniques, such as bisection and secant methods, to find the roots of an equation. It starts with an initial guess and iteratively refines the estimate until it reaches a specified tolerance level.

What is a user-defined function?

A user-defined function is a custom function created by the user to perform a specific task or calculation. In this case, it is used to define the equation that needs to be solved by FZERO.

Can FZERO be used for any type of equation?

FZERO can be used to solve a wide range of equations, including polynomial, transcendental, and differential equations. However, it may not work for all types of equations, and other methods may be more suitable in certain cases.

How accurate is the solution provided by FZERO?

The accuracy of the solution depends on the specified tolerance level and the complexity of the equation. Generally, FZERO provides a highly accurate solution, but it is always recommended to check the results and adjust the tolerance level if needed.

Similar threads

Back
Top