find finverse of cumtrapz()

6 vues (au cours des 30 derniers jours)
Aishwarya Radhakrishnan
Aishwarya Radhakrishnan le 22 Sep 2019
Commenté : Star Strider le 22 Sep 2019
Hi,
I have to invert the function that calculates cumtrapz of an equation as follows:
mu = 0;
var = 1;
%x = -9:0.01:9;
syms x
f(x) = cumtrapz((2*pi*(v))^(-0.5)* exp(-((x-mu).^2)/(2*(v))))
i = finverse(f)
fplot(i)
But this gives me :
f(x) =
0
Warning: Unable to find functional inverse.
> In symengine
In sym/privBinaryOp (line 1032)
In sym/finverse (line 40)
In inverse_cdf (line 7)
i(x) =
Empty sym: 0-by-1
However the cumtrapz function does work:
mu = 0;
var = 1;
x = -9:0.01:9;
y = (2*pi*(v))^(-0.5)* exp(-((x-mu).^2)/(2*(v)));
i = cumtrapz(y);
plot(i)
what can i do to invert this function

Réponse acceptée

Star Strider
Star Strider le 22 Sep 2019
Modifié(e) : Star Strider le 22 Sep 2019
Since ‘f’:
mu = 0;
v = 1;
syms x
f(x) = int((2*pi*(v))^(-0.5)* exp(-((x-mu).^2)/(2*(v))))
evaluates to:
f(x) =
(7186705221432913*2^(1/2)*pi^(1/2)*erf((2^(1/2)*x)/2))/36028797018963968
you will need to use the erfinv function to calculate the inverse.
  3 commentaires
Aishwarya Radhakrishnan
Aishwarya Radhakrishnan le 22 Sep 2019
Modifié(e) : Aishwarya Radhakrishnan le 22 Sep 2019
the cumtrapz calculates the cumulative pdf, but with the inverse function of the cdf, i want to get x in terms of y,
eg, y = F(x)
then x = Finverse(y)
like in figure:
but on using finverse(), im getting error as output
Star Strider
Star Strider le 22 Sep 2019
If you want to use cumtrapz, the interp1 function is likely the best option:
mu = 0;
v = 1;
x = -7:0.01:7;
fx = cumtrapz(1/sqrt(2*pi*(v)) * exp(-((x-mu).^2)/(2*(v))));
y = [5 25 50 75 95];
fi = interp1(fx, x, y, 'linear','extrap')
figure
plot(x, fx)
hold on
plot(fi, y, '+')
hold off
grid
This plots ‘+’ markers at the appropriate values of the ‘y’ vector. I call the inverse ‘fi’. I had to restrict your original ‘x’ vector because with the original vector, the ‘fx’ points were not unique, as interp1 defines that.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by