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

2 vues (au cours des 30 derniers jours)
Danse Groom
Danse Groom le 15 Fév 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

Réponses (1)

Star Strider
Star Strider le 15 Fév 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 commentaires
Danse Groom
Danse Groom le 22 Fév 2020
Thank you!
Star Strider
Star Strider le 22 Fév 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by