MATLAB Using fzero - returns error -


I am trying to use the MATLAB function fzero but my program is an error Reverting message. This is my code (made up of two M-files):

friction_zero.m

  function fric_zero = friction_zero (Reynold) fric_zero = 0.25 * Power (log 10 ( 5.74 / (power(reynolds,0.9)))-2-2);  

flow.m

  function F = flow (fric) f = 1 / (sqrt (fric) - 1.873 * log10 (Reynolds * sqrt ( Fric) - 233 / ((Reynolds * sqrt (Fric)) ^ 0,9) -0,2361; F_initial = friction_zero (power (10.4)); Z = fzero (@flow, f_initial)  

return the target z as the root for the equation specified by f flow.m is run.

I believe that I have the right syntax because I have spent two hours watching the examples. What happens is that it returns the following error message:

"undefined function or variable 'fric'."

(Of course, this is undefined, those variables I am trying to solve!)

Can anyone tell me what I have done? Thanks

Edit

Thanks for all those who helped! After all, you have helped me to find out my problem. I had to add another file here with full output of the entire code with output.

friction_zero.m

function fric_zero = friction_zero (again)

fric_zero = 0.25 * power (log 10 ( 5.74 / (Power (again, 0.9)), - 2); Value for% Fric starts

flow.m

function z = flow (fric)

Re = power (10,4);

z = 1 / (sqrt (fric) - 1.873 * log10 (re * sqrt (fric)) - 233 / ((re * sqrt (fric)) ^ 0.9) -0.2361;

flow2.m

f_initial = friction_zero (again); % Arbitrarily starting value (Reynolds)

x = @flow;

fric_root = fzero (x, f_initial)

This returns an output:

fric_root = 0.0235

That sounds the right answer (OF!)

I realized that (1) I have the right place at Reynolds (which Is not yet defined), and (2) I was trying to do a lot and in this way the line x = @flow; I went out on , when I added an additional line, MATLAB stopped complaining. It is not sure why you have not done this @flow directly ferro () .

Once again, thanks :)

You have to make sure that < Code> f is a function in your code, it is only an expression with reynolds , when it is not defined, then it remains constant, such as the input code Fric with wrap as an anonymous function. Also, you need to make sure that the output variable from your function is z O f . Since you are sorting for fric , you do not need to specify this as the input variable in flows Additionally, you will see f < There is no need to specify / code> as the input in Fuzhou , flow no. Flow is the name of your main function. In addition, the flow is not defined in Reynold , so I'm going to assume that this is what you have on friction_zero Had specified. With these edits, try doing this:

  function z = flows () reynolds = power (10,4); F = @ (fric) 1 / (sqrt (fric) - 1.873 * log10 (Reynolds * sqrt (fric)) - 233 / ((Reynolds * sqrt (fric)) ^ 0.9) -0.2361; F_initial = friction_zero (Reynolds); Z = Ferro (@F, F_Inial); % // You're sorting for `F`, not the flow Flow is your function name  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -