Computing the inverse of function in MATLAB

后端 未结 3 1044
被撕碎了的回忆
被撕碎了的回忆 2021-02-10 17:02

How do you compute the inverse of a function in MATLAB? Say you want to compute the inverse of f(x)=e^x, what would be the code?

3条回答
  •  情话喂你
    2021-02-10 17:41

    Numerical inverse of a monotone Function: let v be a monotone ascending array of numbers (that means v=sort(v)). Then you can derive the inverse (vinv) very simple:

    vinv=cumsum(hist(v,length(v)));

    After this you can beautify the result with a bit of scaling, but basically the cumsum of hist -thingi does the trick.

    You can test the following:

    x=randn(1,1000);
    v=sort(x);
    plot(v);
    vinv=cumsum(hist(v,1000));
    figure(2);
    plot(vinv);
    

提交回复
热议问题