finverse for function handle

5 views (last 30 days)
hello everyone.
how can I find inverse of X_Bi ?
matlab says that unable to find functional inverse.
can you help me please?
clc
clear
close all
R = 8.314;
syms f(x) ;
syms g(x) ;
T_m_Bi = 544;
T_m_Cd = 594;
delta_H0_Bi = 10900;
delta_H0_Cd = 6400;
delta_S0_Bi = 20 ;
delta_S0_Cd = 10.77;
f(x) = 1.2 - (16.45 * x * 10^-3) + (21.1 * x^-2 * 10^5);
g(x) = 7.5 - 12.3 .* 10 .^ (-3) .* x;
G1 = g(x) / x;
F1(x) = f(x) / x;
F = int(f,T_m_Bi,x,'IgnoreAnalyticConstraints',true);
G = int(g,T_m_Cd,x,'IgnoreAnalyticConstraints',true);
F1_prime = int(F1,x,T_m_Bi,x,'IgnoreAnalyticConstraints',true);
G1_prime = int(G1,T_m_Cd,x,'IgnoreAnalyticConstraints',true);
delta_G_Bi(x) = delta_H0_Bi + F - x * (delta_S0_Bi + F1_prime);
delta_G_Cd(x) = delta_H0_Cd + G - x * (delta_S0_Cd + G1_prime);
X_Bi(x) = exp(-delta_G_Bi/(R * x))
X_Bi(x) = 
y = finverse(X_Bi)
Warning: Unable to find functional inverse.
y(x) = Empty sym: 0-by-1
  2 Comments
Jan
Jan on 12 Jul 2022
By the way, 12.3 .* 10 .^ (-3) is ugly and an expensive power operation, whilw 12.3e-3 is a cheap constant.
Why do you assume, that there is an inverse function?
muhammod Abbasi
muhammod Abbasi on 12 Jul 2022
thank you so much.
i just need the inverse of this function, actually i dont know if there is the inverse

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 12 Jul 2022
Edited: John D'Errico on 12 Jul 2022
Does every possible function you write down need to have a functional inverse? Of course not. In fact, it can be proven that functions exist that have no such analytical inverse. Your problem looks very much like such a problem. It is equivalent to a moderately high order polynomial in x. We can ignore the exponential at the end, since you could take the log of the final expression and then have what is effectively a rational polynomial. (Well, not quite, since there will still be a log(x) term inside.)
R = 8.314;
syms f(x) ;
syms g(x) ;
T_m_Bi = 544;
T_m_Cd = 594;
delta_H0_Bi = 10900;
delta_H0_Cd = 6400;
delta_S0_Bi = 20 ;
delta_S0_Cd = 10.77;
f(x) = 1.2 - (16.45 * x * 10^-3) + (21.1 * x^-2 * 10^5);
g(x) = 7.5 - 12.3 .* 10 .^ (-3) .* x;
G1 = g(x) / x;
F1(x) = f(x) / x;
F = int(f,T_m_Bi,x,'IgnoreAnalyticConstraints',true);
G = int(g,T_m_Cd,x,'IgnoreAnalyticConstraints',true);
F1_prime = int(F1,x,T_m_Bi,x,'IgnoreAnalyticConstraints',true);
G1_prime = int(G1,T_m_Cd,x,'IgnoreAnalyticConstraints',true);
delta_G_Bi(x) = delta_H0_Bi + F - x * (delta_S0_Bi + F1_prime);
delta_G_Cd(x) = delta_H0_Cd + G - x * (delta_S0_Cd + G1_prime);
The final expression you get, just before you take the exponential is:
finalExpression = simplify(-delta_G_Bi/(R * x))
finalExpression(x) = 
I'm sorry, but just because you want a solution to exist, this is not enough. No solution will exist there. It is just a little too nasty. Can you use a numerical inverse? Well, yes. But you then need to remember that multiple solutions often may exist, so even fzero may be problematic. For example, if we look at that relationship over several intervals, we can see that for many values on the left hand side, this expression will probably have multiple solutions.
fplot(finalExpression,[0,10])
fplot(finalExpression,[10,50])
fplot(finalExpression,[50,1000])
fplot(finalExpression,[500,10000])
So you could use a tool like fzero, but you will need to provide an intelligent bracket to find the solution you want to see. For example...
fun = matlabFunction(finalExpression);
[x1,fval] = fzero(@(x) fun(x) - 1,[eps,100])
x1 = 69.5357
fval = -1.5543e-15
[x2,fval] = fzero(@(x) fun(x) - 1,[100,1200])
x2 = 999.9492
fval = 4.4409e-16
[x3,fval] = fzero(@(x) fun(x) - 1,[1200,10000])
x3 = 2.0252e+03
fval = 2.2204e-16
As you can see, fzero can find at least three distinct solutions. In each case, a valid numerical solution was obtained. However, I can assure you that no simple algebraic solution will be found.
  1 Comment
muhammod Abbasi
muhammod Abbasi on 12 Jul 2022
thank you so much.
I think you are right. actually this is a thermodynamics problem and i need to find out the inverse . at least I think for solving that problem I need it. this is about phase diagram and I insert the full code below. Actually I was thinking about that i recieve the X_Cd and the T then I say that where it is located based on diagram.
can help me with this please?
clc
clear
close all
R = 8.314;
syms f(x) ;
syms g(x) ;
T_m_Bi = 544;
T_m_Cd = 594;
delta_H0_Bi = 10900;
delta_H0_Cd = 6400;
delta_S0_Bi = 20 ;
delta_S0_Cd = 10.77;
f(x) = 1.2 - (16.45 * x * 10^-3) + (21.1 * x^-2 * 10^5);
g(x) = 7.5 - 12.3 .* 10 .^ (-3) .* x;
G1 = g(x) / x;
F1(x) = f(x) / x;
F = int(f,T_m_Bi,x,'IgnoreAnalyticConstraints',true);
G = int(g,T_m_Cd,x,'IgnoreAnalyticConstraints',true);
F1_prime = int(F1,x,T_m_Bi,x,'IgnoreAnalyticConstraints',true);
G1_prime = int(G1,T_m_Cd,x,'IgnoreAnalyticConstraints',true);
delta_G_Bi(x) = delta_H0_Bi + F - x * (delta_S0_Bi + F1_prime);
delta_G_Cd(x) = delta_H0_Cd + G - x * (delta_S0_Cd + G1_prime);
X_Bi(x) = exp(-delta_G_Bi/(R * x))
y = finverse(X_Bi)
X_Cd(x) = exp(-delta_G_Cd/(R * x));
X1 = matlabFunction(X_Bi);
X2 = matlabFunction(X_Cd);
Y = @(x) X1(x) + X2(x) - 1;
S = fsolve(Y,406);
T = S : 1 : 600;
P = 0 : 0.1 : 1;
x1 = [0 1];
y = [S S];
plot(1-X1(T),T,'g--')
hold on
plot(X2(T),T,'--')
line(x1,y);
axis([0,1,380,600]);
text(0.05,460,'liquid + solid Bi')
text(0.75,460,'liquid + solid Cd')
text(0.5,500,'liquid')
text(0.38,395,'solid Bi + solid Cd')
xlabel('X_C_d');
ylabel('T, K');
x = input('Enter');
t = input('enter');
if x < X1(S)
if t > finverse(X_Bi(x))
disp('LIQUID')
elseif t < finverse(X_Bi(x)) && t > S
disp('LIQUID + SOLID Bi')
else
disp('SOLID Bi + SOLID Cd')
end
else
if t > finverse(X_Cd(x))
disp('LIQUID')
elseif t < finverse(X_Cd(x)) && t > S
disp('LIQUID + SOLID Cd')
else
disp('SOLID Bi + SOLID Cd')
end
end

Sign in to comment.

More Answers (1)

Abderrahim. B
Abderrahim. B on 12 Jul 2022
Not every function has an inverse.
That's a warning not an error and I believe it is because your function does not have an inverse function.

Categories

Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!