What's the best way to solve an equation in this example?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mohamed Abdeldayem
il 18 Lug 2019
Modificato: Peter Jarosi
il 18 Lug 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 Commenti
Risposta accettata
Star Strider
il 18 Lug 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 Commenti
Star Strider
il 18 Lug 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
il 18 Lug 2019
Modificato: Peter Jarosi
il 18 Lug 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.)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Robust Control Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!