
MyFun = xa, ya, za ) cos ( xa ) + sin ( ya ) + za xVals = linspace ( - pi, 2 * pi, 200 ) yVal = pi for k = 1 : length ( xVals ) = fzero zDummy ) MyFun ( xVals ( k ), yVal, zDummy ), 12 ) end The example also assumes an initial guess of 12 for the \(z\) value. It is based on a variable called MyFun that stores the anonymous function, but it could just as well work with a.

FZERO MATLAB CODE
The following example code will do this for 200 values of \(x\) between \(-\pi\) and \(2\pi\). The fzero command can still only solve for a single set of parameters at a time, so you need to construct a loop that will substitute the appropriate \(x\) values into the function and then store the resulting \(z\) value. Now assume that we still set \(y=\pi\) but we want to calculate \(z\) values that make \(f(x,y,z)=0\) for a variety of \(x\) values. Sometimes, there may be a function of multiple variables where you want to find the value of the root as a function of one or more parameters of the function. In each of the examples above, there was only one variable that MATLAB had control over everything else remained constant. OPTIONS are.optional - the most common is the command.m file function, or a calculation - whatever it is that you are trying to set equal to zero note that DUMMY_VAR must appear somewhere in this expression for fzero to be able to do anything FUNCTION_THING can be a built-in function, the name of an anonymous function, the name of a.

INIT_STUFF is either an initial guess or a valid initial bracket - note that fzero can only find one root at a time, so you cannot load this with several values and try to have fzero find multiple results (for that, you need loops).DUMMY_VAR is the variable you want to use in this FUNCTION_THING to indicate which of the various inputs fzero is allowed to alter.VAL_AT_ROOT is the value of the function when substituting ROOT for the requested variable - nominally this is 0 but there may be roundoff issues to deal with.ROOT is the calculated value of the requested variable when the function is 0.= fzero DUMMY_VAR ) FUNCTION_THING, INIT_STUFF, OPTIONS )
