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

2 Ansichten (letzte 30 Tage)
Danse Groom
Danse Groom am 15 Feb. 2020
Bearbeitet: Walter Roberson am 22 Feb. 2020
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

Antworten (1)

Star Strider
Star Strider am 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.
  2 Kommentare
Star Strider
Star Strider am 22 Feb. 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by