Borrar filtros
Borrar filtros

How to get fzero with 2 variables in array?

7 visualizaciones (últimos 30 días)
Nabilla Dewi Septiani
Nabilla Dewi Septiani el 8 de Dic. de 2021
Comentada: Nabilla Dewi Septiani el 9 de Dic. de 2021
I want to get the x value for each y and alpha in array. But I got error like this
Error using fzero (line 274)
Function values at the interval endpoints must differ in sign.
Error in Term_Paper (line 14)
x(i)=fzero(@(y)dot(tp,fx(x)),[0.15 1]);
How to solve this?
%Parameters
xin=0.2; xout=0.1; Pr=0.3; qf=1;
y=0:0.1:1;
alpha=0:100:1000;
%For Cross-Flow Module (CF)
%y=(1+(x+Pr).*(alpha-1))-((1+(x+Pr).*(alpha-1)).^2-(4.*alpha.*(alpha-1).*x.*Pr)).^0.5/(2.*Pr.*(alpha-1))
%Calculating x
fx=@(x) ((1+((x+Pr).*(alpha-1))-((((1+((x+Pr).*(alpha-1))).^2)-(4.*alpha.*(alpha-1).*x.*Pr)).^0.5))/(2.*Pr.*(alpha-1)))-y;
x=zeros(size(fx(0.16)));
for i=1:length(x)
tp=zeros(size(x));
tp(i)=1;
x(i)=fzero(@(y)dot(tp,fx(x)),[0.15 1]);
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Dic. de 2021
I'm trying to solve fzero for each value of x in an array, and I get theis error:
Don't Do That.
fzero() is defined as only accepting scalar equations of one variable. It cannot in itself be used to solve at multiple x values simultaneously
You need to loop through the different alpha and y values. Your code would produce one output for each alpha and each y, so you need to output a 2D grid -- unless, that is, you intend each of those alpha values to be matched with a corresponding y value (as you have 11 of each): in that case you would only need a a vector output for each fzero system
arrayfun(@(ALPHA, Y) fzero(@(x) ((1+((x+Pr).*(ALPHA-1))-((((1+((x+Pr).*(ALPHA-1))).^2)-(4.*ALPHA.*(ALPHA-1).*x.*Pr)).^0.5))/(2.*Pr.*(ALPHA-1)))-Y), alpha, y)

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by