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

 채택된 답변

Walter Roberson
Walter Roberson 2021년 12월 8일

0 개 추천

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)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Optimization에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

Community Treasure Hunt

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

Start Hunting!

Translated by