Guest User

Untitled

a guest
Feb 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. RealInverse[a_. x_^q_Integer?Positive + b_., x_] /; FreeQ[{a, b}, x] :=
  2. Surd[(x-b)/a, q]
  3.  
  4. RealInverse[expr_, x_] :=
  5. Module[{y, red},
  6. red = Reduce[x == (expr /. x -> y), y, Reals];
  7. ToPW[PWTerm[#, y]& /@ OrList[BooleanConvert[red, "DNF"]], x]
  8. ]
  9.  
  10. OrList[HoldPattern[Or][args__]] := {args}
  11. OrList[e_] := {e}
  12.  
  13. PWTerm[And[cond1___, y_ == root_, cond2___], y_] /; FreeQ[{root, And[cond1, cond2]}, y] := {root, And[cond1, cond2]}
  14. PWTerm[y_ == root_, y_] /; FreeQ[root, y] := {root, True}
  15. PWTerm[___] = $Failed;
  16.  
  17. ToPW[lis_?MatrixQ, x_] /; Length[First[lis]] == 2 :=
  18. With[{condlist = Last[Transpose[lis]]},
  19. Piecewise[lis, Undefined] /; DisjointConditionsQ[condlist, x]
  20. ]
  21. ToPW[___] = $Failed;
  22.  
  23. DisjointConditionsQ[{_}, _] = True;
  24. DisjointConditionsQ[cond_List, x_]:=
  25. Reduce[And @@ Table[DisjointCondition[cond, i], {i, Length[cond]}], x]
  26.  
  27. DisjointCondition[cond_, i_] :=
  28. If[TrueQ[cond[[i]]],
  29. True,
  30. Implies[cond[[i]], Not[And @@ Delete[cond, i]]]
  31. ]
  32.  
  33. RealInverse[x^3, x]
  34.  
  35. Surd[x, 3]
  36.  
  37. RealInverse[x^7 + x^4 + 3 x - 1, x]
  38.  
  39. Root[-1 - x + 3 #1 + #1^4 + #1^7 &, 1]
  40.  
  41. (* Not invertible over the real line *)
  42. RealInverse[x^3 - 3 x + 1, x]
  43.  
  44. $Failed
  45.  
  46. RealInverse[x^(2/3) + Sqrt[x], x]
  47.  
  48. ConditionalExpression[
  49. Root[x^6 - 3 x^4 #1 + (3 x^2 - 2 x^3) #1^2 + (-1 - 6 x) #1^3 + #1^4 &, 1],
  50. x >= 0
  51. ]
  52.  
  53. RealInverse[Sign[x] (Abs[x]^(2/3) + Sqrt[Abs[x]]), x]
  54.  
  55. inverseFunc[x_] = x /. Solve[x^3 == y, x, Reals][[1]] /. y -> x;
  56. N@inverseFunc[3]
  57. N@inverseFunc[-1]
  58. (*1.44225*)
  59. (*-1.*)
  60.  
  61. x /. Solve[x^3 == y, x, Reals]
  62. (* {Root[-y + #1^3 &, 1]} *)
  63. Plot[%, {y, -10, 10}, AxesLabel -> {y, x}]
  64.  
  65. invfun[g_] := N[x /. First@Solve[g[x] == #, x, Reals]] &
  66.  
  67. f[x_] := x^3
  68.  
  69. invfun[f][y]
  70.  
  71. Plot[invfun[f][y], {y, -10, 10}, AxesLabel -> {y, x}]
Add Comment
Please, Sign In to add comment