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

2 ビュー (過去 30 日間)
Danse Groom
Danse Groom 2020 年 2 月 15 日
編集済み: Walter Roberson 2020 年 2 月 22 日
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.
  2 件のコメント
Danse Groom
Danse Groom 2020 年 2 月 22 日
Thank you!
Star Strider
Star Strider 2020 年 2 月 22 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by