finverse for function handle
5 views (last 30 days)
Show older comments
muhammod Abbasi
on 12 Jul 2022
Commented: muhammod Abbasi
on 12 Jul 2022
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))
y = finverse(X_Bi)
2 Comments
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?
Accepted Answer
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))
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])
[x2,fval] = fzero(@(x) fun(x) - 1,[100,1200])
[x3,fval] = fzero(@(x) fun(x) - 1,[1200,10000])
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.
More Answers (1)
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.
See Also
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!