unction file
function y = f(x,a,A,b,Ttx,gamma_b)
y = ((a./A)-(((1+gamma_b)/2)*(b./Ttx)));
end
script and error
>> xVec=0:0.01:0.4; %axial combuster length (can be varied according to user input and units)
xi=xVec(1); %station 3 (combuster starting point)
x4=xVec(end);%station 4 (combuster end point)
gamma_b=1.36;%Average value of ratio of specific heat capacities during burning
gamma_c=1.4;%Average value of ratio of specific heat capacities during compression
X=((xVec-xi)/(x4-xi));
a3=0.0038;%station 3 cross secion area in m2.
A=a3*(1+X);%Area Profile
a=gradient(A,xVec);%dA/dx in equation (6-90)
a1Vec=a./A; %(dA/dx)/A in equation (6-90)
tau_b=1.5; %Tt4/Tt2 in eq. (6-91) overall total temerature rise in burner
theta=2;%emperical constant in eq. (6-91)
Tt2=2200;%Total temperature at station 2 depends on inlet and compression conditions (USER SPECIFIED)
Ttx=Tt2*(1+(tau_b-1)*((theta*X)./(1+(theta-1)*X)));%Temperature profile eq. (6-91)
b=gradient(Ttx,xVec);%dTt/dx in equation (6-90)
b1Vec=b./Ttx;%(dTt/dx)/Tt in equation (6-90)
fun = @f; % function
x0 = 0; % initial point
z = fzero(fun,x0);
Error using fzero (line 289)
FZERO cannot continue because user supplied function_handle ==> f failed with the error below.
Not enough input arguments.

 채택된 답변

Joe
Joe 2015년 7월 17일

0 개 추천

Assuming that you are trying to find x such that the equation you posted to Star Strider is satisfied, there are two ways to do what you want. The first is essentially a brute-force numerical minimization. Since you've computed the area, temperature field, and respective derivatives numerically, you can just take the absolute minimum of the function and use that X-value as your solution. Assuming the script posted above, you can write:
fun = @(x)((a./A)-(((1+gamma_b)/2)*(b./Ttx))); % Function of x only
[fMin, idx] = min(abs(fun(X)));
xMin = X(idx);
% Verify with plot
plot(X, fun(X), xMin, fMin, 'o');
For better resolution, just reduce the step size in 'xVec.' (If I used the wrong variables above, I hope you still get the idea).
Your other option is to write out the analytical values and derivatives for A, dA/dx, Tt, and dTt/dx. Then, incorporate them all into the function so that it a function of X only. Fzero will work for you then. If you give it numerical derivatives, as you're doing here, there's no way it can zero the function for you.
You could also look into ode45 but that's probably more trouble than it's worth.

추가 답변 (1개)

Brendan Hamm
Brendan Hamm 2015년 7월 17일

0 개 추천

Your objective function can only take one input argument, so the idea of the function handle is to make an anonymous function:
fun = @(x) f(x,a,A,b,Ttx,gamma_b);
This will make fun only take one input variable and will hardcode the other values from your workspace into the function's workspace.

댓글 수: 5

Matt J
Matt J 2015년 7월 17일
편집: Matt J 2015년 7월 17일
In addition, f doesn't appear to actually depend on x in any way. It's just returning some constant, and that constant doesn't appear to be a scalar.
i
>> xVec=0:0.01:0.4; %axial combuster length (can be varied according to user input and units)
xi=xVec(1); %station 3 (combuster starting point)
x4=xVec(end);%station 4 (combuster end point)
gamma_b=1.36;%Average value of ratio of specific heat capacities during burning
gamma_c=1.4;%Average value of ratio of specific heat capacities during compression
X=((xVec-xi)/(x4-xi));
a3=0.0038;%station 3 cross secion area in m2.
A=a3*(1+X);%Area Profile
a=gradient(A,xVec);%dA/dx in equation (6-90)
a1Vec=a./A; %(dA/dx)/A in equation (6-90)
tau_b=1.5; %Tt4/Tt2 in eq. (6-91) overall total temerature rise in burner
theta=2;%emperical constant in eq. (6-91)
Tt2=2200;%Total temperature at station 2 depends on inlet and compression conditions (USER SPECIFIED)
Ttx=Tt2*(1+(tau_b-1)*((theta*X)./(1+(theta-1)*X)));%Temperature profile eq. (6-91)
b=gradient(Ttx,xVec);%dTt/dx in equation (6-90)
b1Vec=b./Ttx;%(dTt/dx)/Tt in equation (6-90)
fun = @(x)((a./A)-(((1+gamma_b)/2)*(b./Ttx))) ; % function
x0 = [0 0.4]; % initial interval
options = optimset('Display','iter'); % show iterations
[x fval exitflag output] = fzero(fun,x0,options)
Error using fzero (line 274) The function values at the interval endpoints must differ in sign. bold
i tried it that way too but still its not working.
Matt J
Matt J 2015년 7월 17일
Error using fzero (line 274) The function values at the interval endpoints must differ in sign.
See my previous comment. FZERO cannot find interval endpoints differing in sign because your function can return only one possible value.
but its has different values at xvec=0 and xvec=0.4 and these are -1.8902 and +0.49058.

댓글을 달려면 로그인하십시오.

카테고리

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

태그

질문:

2015년 7월 17일

답변:

Joe
2015년 7월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by