Find the roots of an expression

Is there a function that can find the root(s) of an expression, which is not a polynomial? My constants and my final expression (for which I want to find the root) are listed below.
%Declare constants
Dw = 0.0000076;
S = 0.000239;
rho = 1.1;
h = 0.0030;
Nm=20,000;
Wo = 0.0025;
c1 = Dw*S/rho/h;
c2 = (3*Wo/(4*Nm*3.14159*rho))^(1/3);
c3 = (3*Wwf/(4*Nm*3.14159*rho))^(1/3);
twf=20;
%Need to determine the value of Wwf in the following expression
((c2 - c3 - h*log((h + c2)/(h + c3)))/c1)-twf=0;

 Réponse acceptée

Matt Fig
Matt Fig le 13 Avr 2011

0 votes

FZERO can be used to find roots.
Dw = 0.0000076;
S = 0.000239;
rho = 1.1;
h = 0.0030;
Nm=20000;
Wo = 0.0025;
c1 = Dw*S/rho/h;
c2 = (3*Wo/(4*Nm*3.14159*rho))^(1/3);
c3 = @(Wwf) (3*Wwf/(4*Nm*3.14159*rho)).^(1/3);
twf=20;
G = @(Wwf) ((c2 - c3(Wwf) - h*log((h + c2)./(h + c3(Wwf))))/c1)-twf;
rt = fzero(G,.01)

5 commentaires

Deanna
Deanna le 13 Avr 2011
Thanks!
John D'Errico
John D'Errico le 13 Avr 2011
Note that fzero finds A root, based on the starting value. It will not return all roots of a nonlinear expression, something quite difficult to do in general.
Deanna
Deanna le 13 Avr 2011
I have another question. How can this code be written as part of a loop, where different values of twf were evaluated? I tried to do it (see code below), but I get the error message:
??? The following error occurred converting from function_handle to
double:
Error using ==> double
Conversion to double from function_handle is not possible.
Error in ==> fzero_1 at 25
c3(i) = @(Wwf) (3*Wwf/(4*Nm*3.14159*rho)).^(1/3);
Code:
clear all
Dw = 0.0000076;
S = 0.000239;
rho = 1.1;
h = 0.0030;
Nm=20000;
Wo = 0.0025;
c1 = Dw*S/rho/h;
c2 = (3*Wo/(4*Nm*3.14159*rho))^(1/3);
%initializations
twf(1)=1;
c3(1)=c2;
rt(1)=Wo;
i=1;
for i=2:10800
c3(i) = @(Wwf) (3*Wwf/(4*Nm*3.14159*rho)).^(1/3);
G(i) = @(Wwf) ((c2 - c3(Wwf) - h*log((h + c2)./(h + c3(Wwf))))/c1)-twf(i-1);
rt(i) = fzero(G(i),.01);
twf(i)=i;
end
Thanks!
Matt Fig
Matt Fig le 13 Avr 2011
Try this:
Dw = 0.0000076;
S = 0.000239;
rho = 1.1;
h = 0.0030;
Nm=20000;
Wo = 0.0025;
c1 = Dw*S/rho/h;
c2 = (3*Wo/(4*Nm*3.14159*rho))^(1/3);
%initializations
twf(1)=1;
c3=@(Wwf) (3*Wwf/(4*Nm*3.14159*rho)).^(1/3);
rt = zeros(1,10800);
rt(1) = Wo;
for ii=2:10800
G = @(Wwf) ((c2 - c3(Wwf) - h*log((h + c2)./(h + c3(Wwf))))/c1)-(ii-1);
try
rt(ii) = fzero(G,rt(ii-1));
catch
disp('No value found, aborting....')
rt = rt(1:ii-1);
break
end
end
Deanna
Deanna le 13 Avr 2011
Yes, thanks, that works as long as I end the loop early enough. For the code about 10800 is too many iterations.

Connectez-vous pour commenter.

Plus de réponses (1)

Deanna
Deanna le 13 Avr 2011

0 votes

The following works. For the constants I gave I need to end the loop at 2600. If the loop runs longer an error occurs.
clear all
Dw = 0.0000076;
S = 0.000239;
rho = 1.1;
h = 0.0030;
Nm=8477.7;
Wo = 0.0025;
c1 = Dw*S/rho/h;
c2 = (3*Wo/(4*Nm*3.14159*rho))^(1/3);
%initializations
c3=@(Wwf) (3*Wwf/(4*Nm*3.14159*rho)).^(1/3);
rt = zeros(1,2600);
rt(1) = Wo;
time(1)=0;
for ii=2:2600
G = @(Wwf) ((c2 - c3(Wwf) - h*log((h + c2)./(h + c3(Wwf))))/c1)-(ii-1);
rt(ii) = fzero(G,[0 0.0025]);
time(ii)=time(ii-1)+ii;
end

Catégories

En savoir plus sur Performance and Memory dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by