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

3 views (last 30 days)
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

Answers (1)

Star Strider
Star Strider on 15 Feb 2020
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.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!