Matlab Cannot Find Functional Inverse

47 vues (au cours des 30 derniers jours)
Tom Keaton
Tom Keaton le 1 Fév 2019
Commenté : John D'Errico le 5 Fév 2019
Hello, I have this code and want to find the inverse of the defined function, however Matlab says it is unable (Error below) and doesn't explicilty state why. Is it because there is an error function involved?
Code:
%User inputs
maxeV = 2000; %Maximum potential in system (in eV)
T = 66661.2; %Pressure in Pascals
%Constants
m_e = 9.11E-31; %Electron mass
k = 1.381E-23; %Boltzman's constant
con = 4*pi*(m_e/(2*pi*k*T))^(3/2); %constant infront of Maxwellian distribution function
syms ven
maxd = con*(ven^2)*exp((-m_e*ven^2)/(2*k*T)); %Define Maxwellian distribution function
Peint = int(maxd); %Integrate function to get probability-error function
Peinv = finverse(Peint); %Invert p-e function
Error:
Warning: Unable to find functional inverse.
> In symengine
In sym/privBinaryOp (line 991)
In sym/finverse (line 40)

Réponses (1)

John D'Errico
John D'Errico le 2 Fév 2019
Modifié(e) : John D'Errico le 2 Fév 2019
No. It is because there is no analytically writable inverse that it can find.
Look at what you have done. Don't just compute something and stop thinking. Never assume the computer can do anything at all you give it to do.
pretty(vpa(Peint,6))
-7 -13 2 -7
- erfi(ven (7.03414 10 )) 1.0i - ven exp(-4.94791 10 ven ) 7.93717 10
So Peint has terms of the general form
a*erfi(b*ven)*i + c*ven*exp(d*ven^2)
erfi is the imaginary error function. But you also have ven appearing inside and outside an exponential, with ven^2 inside.
>> help erfi
--- help for double/erfi ---
erfi Imaginary error function.
Y = erfi(x) computes the value of the imaginary error function
for the argument x.
The imaginary error function is defined in terms of the error function
ERF via erfi(i*x) = -i*erf(-x).
So while that imaginary error function can actually be converted back into a simple error function because i^2=-1, but the result will still be that no analytical solution does exist or will be found.
Mathematics is full of things that are trivial to write, yet still impossible to solve, to write an answer.
fplot(Peint)
So you need to think about how to find the inverse at any point. For example, the inverse of Peint is given by solving for that value of ven, such that
y - Peint(ven) == 0
You can use vpasolve, or you could theoretically use fzero. (fzero will tend to fail however, unless you are quite careful, due to the dynamic range of the numbers involved.)
But remember that vpasolve is not an analytical solution. You will not get some nice function out that you can plot, use, or even write down. Nothing will give you that.
  2 commentaires
Tom Keaton
Tom Keaton le 4 Fév 2019
So I realized there were a few issues with my function in the first place.
maxeV = 2000; %Maximum potential in system (in eV)
T = 1000; %Temp in K
%P = %Pressure in Pascals
%Constants
q_e = -1.602E-19; %Electron charge
m_e = 9.11E-31; %Electron mass
k = 1.381E-23; %Boltzman's constant
cone = 2/((k*T)^(3/2));
Bmax = 0.5; %Maximum B-field in experiment
%Calculate max energy in system
Ejmax = maxeV*(1.602E-19); %Maximum energy an electron may have
Ejmin = 0; %Minimu menergy an electron may have
vmagmax = Ejmax/(0.5*m_e); %Max velocity magnitude of electron given max energy
%Create Maxwellian distribution function (In terms of E)
syms Ein Eout E x
maxd2 = cone*sqrt(Ein/pi)*exp(-Ein/(k*T)); %Define Maxwellian distribution function
Peint2 = int(maxd2,[0 x]); %Integrate function to get probability-error function
Peinv2 = finverse(Peint2,x);
%Peinv2 = erfinv(Peint2) %Invert p-e function
fplot(Peinv2,[0,1E-18])
However, even with it changing slightly, the issue still persists and I think it goes farther than the solution you provided. I have tried multiple ways to do a numerical approximation inverse of this function and looked up other threads where people had similar issues and it seems that it really jsut comes down to the way Matlab defines its own arbitrary functions, making it not able to solve certain equations/functions.
John D'Errico
John D'Errico le 5 Fév 2019
pretty(vpa(Peint2,5))
19 9 19
1.0 - sqrt(x) exp(-7.2411 10 x) 9.6019 10 - 1.0 erfc(sqrt(7.2411 10 x))
Ok. You changed it. But that does not make an inverse exist.
These are not arbitrary functions. erfc is a pretty standard function, commonly known as a special function, but very well known in mathematics. It is normally written in terms of an integral, but an integral that is used so frequently in mathematics that a name has been assigned to that integral.
This is not any different from defining a function called exp(x) or even sin(x), functions that just happen to be incredibly useful in mathematics, sufficiently so that they have been given their own names. Bessel functions also come to mind, lambertW, etc. This is just mathematics. Nobody is just making up random names here, with arbitrary functions.
If you have no clue as to what erfc means, I think you might do some reading in references like Abramowitz & Stegun.
Does a solution exist? Well, it might. Anything is possible, given sufficient skill in driving the tools at hand, and sufficient knowledge of mathematics. I can think of a blog post by Cleve Moler, where he poses a problem where a direct approach using symbolic tools fails, yet, by careful transformations of the problem, a solution does drop out. Again, just good mathematics.
So if I look at the expression you have derived, perhaps what is needed is some good mathematical thinking on your part, because the expression you show there seems highly unlikely to have a direct solution. But hey, what do I know?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by