What's the best way to solve an equation in this example?

1 view (last 30 days)
I have a group of anonuyms functions that all depend on one missing varaible
This is my code:
A = @(D) pi/4*D^2;
V = @(D) Q/A(D)
Re = @(D) (rho_10*V(D)*D)/mu;
f = @(D) ffactor(Re(D), e/D);
dH = @(D) (f(D) * L/D + K)*((V(D)^2)/2) ;
% D^3 = (Q/n*Q`)^1/3
RPM = linspace(900,1800,100)/60;
Hp = (Hbep/Hc).*RPM.^2.*DD.^2;
dd(100) = 0; d_guess = 6/12;
for i=1:100
F=@(D) (H2-H0+dH(D)) - Hp(i);
dd(i) = fzero(F,d_guess);
d_guess = dd(i); %feet
end
fzero here is being used to find the value of D. My issue is fzero requires an initial value, x0 (d_guess = 6/12 in this was used). I would like to make this a function that would not require an intial value to evaluate. How would I do this?

Accepted Answer

Star Strider
Star Strider on 18 Jul 2019
Try this:
myFZERO = @(F) fzero(F, 10); % Hard-Coded Initial Estimate
a = @(x) x.^2-5; % Test Function
dd = myFZERO(a) % Test Result
producing (here):
dd =
2.2361
  3 Comments
Star Strider
Star Strider on 18 Jul 2019
‘Not really sure what is the purpose of this.
It uses a default initial estimate, so you don’t have to specifically provide one when you call it.
‘Is there a way to use fzero without giving it an estimiate?
No.
That is also true for every solver I am aware of.
Peter Jarosi
Peter Jarosi on 18 Jul 2019
Edited: Peter Jarosi on 18 Jul 2019
‘Is there a way to use fzero without giving it an estimiate?
'No.'
'That is also true for every solver I am aware of.'
I totally agree with your answer 'No'. It's not just because of the solver. Having a nonlinear equation system there is most likely a chance for multiple solutions. For instance, consider x^2 - 4 = 0. That's why nonlinear solver needs initial value in order to get the 'nearest' solution to it. Only linear equation system doesn't need initial value (and some special cases of nonlinear systems but this is advanced math.)

Sign in to comment.

More Answers (0)

Categories

Find more on Robust Control Toolbox in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!