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

  • Thread starter Thread starter George3
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The discussion focuses on solving a MATLAB homework problem involving the use of the fzero function to model water volume in a reservoir over time. The user is required to create two user-defined functions: one to define the water volume function V(t) and another to compute the time required for the water volume to decrease to a specified percentage of its initial value. The provided code snippets demonstrate an attempt to implement these functions, but the user encounters issues with obtaining the correct time output. Key functions discussed include MATLAB's fzero and the mathematical modeling of water volume based on consumption rates.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with the fzero function in MATLAB
  • Basic knowledge of exponential functions and their applications
  • Concept of modeling real-world scenarios using mathematical equations
NEXT STEPS
  • Review MATLAB documentation on the fzero function for advanced usage
  • Explore how to implement global variables effectively in MATLAB
  • Learn about debugging techniques in MATLAB to identify issues in code
  • Investigate numerical methods for solving equations in MATLAB
USEFUL FOR

Students studying engineering or mathematics, MATLAB programmers, and anyone involved in numerical modeling of real-world systems.

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?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
9K
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
1
Views
2K
Replies
1
Views
3K