Borrar filtros
Borrar filtros

how can I remove error in fzero?

6 visualizaciones (últimos 30 días)
Parham Babakhani Dehkordi
Parham Babakhani Dehkordi el 2 de Abr. de 2015
Comentada: Torsten el 2 de Abr. de 2015
Hi everybody, I have some input parameters such as: D=0.040; A=pi*D^2/4; Jo=0.74; Jw=[0.35 0.25 0.19 0.12 0.08 .06 0.04]; ro_o=910; ro_w=1000; mu_w=0.001; mu_o=0.92;
for p=1:length(Jw)
fun=@(Hw,Jw) (((8*ro_o*((D-(2*sqrt(Hw*A/pi)))*(Jo/(1-Hw))*ro_o/mu_o)^-1.0)*(Jo/(1-Hw))^2)*(pi*(D-(2*sqrt(Hw*A/pi)))*(1/(1-Hw))))-((0.023*((Jw(p)*D*ro_w/mu_w)^-.2)*ro_w*(Jw(p)/Hw)^2*pi*D)) ;
Hw(p)=fzero(@(Hw) fun(Hw,Jw(p)),[0 0.4]);
end
if I run this, I would get an error as follows: Error using fzero (line 242) Function values at interval endpoints must be finite and real.
Error in by_using_fminbnd (line 21) Hw(p)=fzero(@(Hw) fun(Hw,Jw(p)),[0 0.4]);
Thus, I tried to use fsolve, it is good but the results have imaginary part which I do not want it, my result must be real positive values, I wrote the codes for fsolve:
for p=1:length(Jw)
Hw(p) = fsolve(@(Hw) (((8*ro_o*((D-(2*sqrt(Hw*A/pi)))*(Jo/(1-Hw))*ro_o/mu_o)^-1.0)*(Jo/(1-Hw))^2)*(pi*(D-(2*sqrt(Hw*A/pi)))*(1/(1-Hw))))-((0.023*((Jw(p)*D*ro_w/mu_w)^-.2)*ro_w*(Jw(p)/Hw)^2*pi*D)), 0.4)
end
is there anybody to help me?

Respuesta aceptada

Parham Babakhani Dehkordi
Parham Babakhani Dehkordi el 2 de Abr. de 2015
D=0.040; A=pi*D^2/4; Jo=0.74; Jw=[0.35 0.25 0.19 0.12 0.08 .06 0.04]; ro_o=910; ro_w=1000; mu_w=0.001; mu_o=0.92;
fun=@(Hw,Jw) (((8*ro_o*((D-(2*sqrt(Hw*A/pi)))*(Jo/(1-Hw))*ro_o/mu_o)^-1.0)*(Jo/(1-Hw))^2)*(pi*(D-(2*sqrt(Hw*A/pi)))*(1/(1-Hw))))-((0.023*((Jw*D*ro_w/mu_w)^-.2)*ro_w*(Jw/Hw)^2*pi*D)) ;
for p=1:length(Jw)
Hw(p)=fzero(@(Hw) fun(Hw,Jw(p)),[-0.4 0.4]);
end
your guess is right, this an error again:
Error using fzero (line 242) Function values at interval endpoints must be finite and real.
Error in by_using_fminbnd (line 21) Hw(p)=fzero(@(Hw) fun(Hw,Jw(p)),[-0.4 0.4]);
Do you have any other functions or approach that you can suggest me to avoid going to an infinite value?
  2 comentarios
Parham Babakhani Dehkordi
Parham Babakhani Dehkordi el 2 de Abr. de 2015
D=0.040; A=pi*D^2/4; Jo=0.74; Jw=[0.35 0.25 0.19 0.12 0.08 .06 0.04]; ro_o=910; ro_w=1000; mu_w=0.001; mu_o=0.92;
fun=@(Hw,Jw) (((8*ro_o*((D-(2*sqrt(Hw*A/pi)))*(Jo/(1-Hw))*ro_o/mu_o)^-1.0)*(Jo/(1-Hw))^2)*(pi*(D-(2*sqrt(Hw*A/pi)))*(1/(1-Hw))))-((0.023*((Jw*D*ro_w/mu_w)^-.2)*ro_w*(Jw/Hw)^2*pi*D)) ;
for p=1:length(Jw)
Hw(p)=fzero(@(Hw) fun(Hw,Jw(p)),[-0.4 0.4]);
end
your guess is right, this an error again:
Error using fzero (line 242) Function values at interval endpoints must be finite and real.
Error in by_using_fminbnd (line 21) Hw(p)=fzero(@(Hw) fun(Hw,Jw(p)),[-0.4 0.4]);
Do you have any other functions or approach that you can suggest me to avoid going to an infinite value?
Torsten
Torsten el 2 de Abr. de 2015
You have sqrt(Hw*A/pi) in your formula for the function.
sqrt(-0.4*A/pi) gives a complex number ...
Best wishes
Torsten.

Iniciar sesión para comentar.

Más respuestas (1)

Torsten
Torsten el 2 de Abr. de 2015
In your function definition, you divide by Hw. Thus your left interval endpoint is not allowed to be 0.
Further:
Did you test that your function produces results of different sign at the endpoints of the interval ? My guess is no since you did not recognize that f(0)=Infinity.
Further you should use:
D=0.040; A=pi*D^2/4; Jo=0.74; Jw=[0.35 0.25 0.19 0.12 0.08 .06 0.04]; ro_o=910; ro_w=1000; mu_w=0.001; mu_o=0.92;
fun=@(Hw,Jw) (((8*ro_o*((D-(2*sqrt(Hw*A/pi)))*(Jo/(1-Hw))*ro_o/mu_o)^-1.0)*(Jo/(1-Hw))^2)*(pi*(D-(2*sqrt(Hw*A/pi)))*(1/(1-Hw))))-((0.023*((Jw*D*ro_w/mu_w)^-.2)*ro_w*(Jw/Hw)^2*pi*D)) ;
for p=1:length(Jw)
Hw(p)=fzero(@(Hw) fun(Hw,Jw(p)),[0 0.4]);
end
Best wishes
Torsten.

Categorías

Más información sobre Sensitivity Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by