MATLAB Answers

1

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

Asked by Mohamed Abdeldayem on 18 Jul 2019
Latest activity Edited by Peter Jarosi on 18 Jul 2019
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?

  0 Comments

Sign in to comment.

Products


Release

R2019a

1 Answer

Answer by Star Strider
on 18 Jul 2019
 Accepted Answer

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

Not really sure what is the purpose of this. I am trying to avoid using fzero because the way I want to make my function is I would call it and it should be able to find D without having to input an initial estimate for it. Is there a way to use fzero without giving it an estimiate?
‘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.
‘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.