How to use fzero to solve for a variable in an exponent?

2 次查看(过去 30 天)
I am trying to use fzero to find where two equations are equal to one another with respect to T, by setting them equal to one another and then subtraction one side from the other, f(t) - g(t) = 0. When I run the code posted below I dont get any error messages but nothing is printed out. Any Help would be greatly appreciated.
X1 = 0.5;
X2 = 0.5;
A12 = 1.6798;
A21 = 0.9227;
AW = 7.96681;
BW = 1668.21;
CW = 228.00;
AE = 8.04494;
BE = 1554.3;
CE = 222.65;
P = 763.712697;
gam1 = exp(A12*((A21*X2)/(A12*X1+A21*X2))^2);
gam2 = exp(A21*((A12*X1)/(A12*X1+A21*X2))^2);
function y = f(T)
y = gam1*X1*10^(AE - BE/(T+CE)) + (gam2*X2*10^(AW - BW/(T+CW))-P);
fun = @f; % function
T0 = 2; % initial point
z = fzero(fun,T0)
end

回答(1 个)

Star Strider
Star Strider 2020-2-15
Take the fzero call out of the function it calls:
X1 = 0.5;
X2 = 0.5;
A12 = 1.6798;
A21 = 0.9227;
AW = 7.96681;
BW = 1668.21;
CW = 228.00;
AE = 8.04494;
BE = 1554.3;
CE = 222.65;
P = 763.712697;
gam1 = exp(A12*((A21*X2)/(A12*X1+A21*X2))^2);
gam2 = exp(A21*((A12*X1)/(A12*X1+A21*X2))^2);
function y = f(T)
y = gam1*X1*10.^(AE - BE./(T+CE)) + (gam2*X2*10.^(AW - BW./(T+CW))-P);
end
fun = @f; % function
T0 = 2; % initial point
z = fzero(fun,T0)
to get:
z =
80.0550
I also vectorised the ‘y’ assignment.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by