Message Boards Message Boards


Interpolating functions for inverting equations

Posted 10 years ago
1 Reply
2 Total Likes
Hey guys!

I'm trying to model a system, mainly how it gives off energy over time depending on a number of paramters.
For that I have a number of expressions containing all kinds of stuff (Tanh[], Log[] etc.) and I would like to know their primitive or their inverse functions to plot them or use it for further calculations.
However, as I am adding more and more complexity, their seems to be no analytial solution (using Solve, Reduce, Inverse or Integrate) in some cases (or at least I am not getting one) and I don't know how to tackle the problem.

Now, since the graphs these expressions give me are usually very 'simple' my idea was to approximate them with a function that is easier to manipulate.

However, the closest I was able to find is FunctionInterpolation[] but that doesn't give me a new function and I have no idea what type of approximation is used.
As for all the other fit commands, the seem to refer to pairs of numbers etc. Isn't there a way to say I want to let's say approximate f(x) with a third degree polynomial as accurately as possible within {x1,x2}?

Here's an example:
This Function gives me t(s) and I want s(t) to put in into another equation. I do have numerical values for all other parameters.
  s_, \[CapitalDelta]h_, \[Rho]_, \[Lambda]_, \[CurlyTheta]e_, \
\[CurlyTheta]o_, dw_, \[Lambda]w_, \[Alpha]f_, r_] := (
s^2 \[CapitalDelta]h \[Rho] (-(3/2) + (3 \[Lambda])/(
    dw \[Alpha]f - r \[Alpha]f) + (
    3 \[Lambda] Log[r/(-dw + r)])/\[Lambda]w + ((r + s)^2 Log[(r + s)/
      r])/s^2))/(2 (\[CurlyTheta]e - \[CurlyTheta]o) \[Lambda])

Any help is greatly appreciated!

So, your question is "How to obtain an inverse function x(y) for a given y(x)"?
You can do this quite easy when x(y) is given numerically as InterpolatingFunction object.
Here is how it can be done:
 (* your function y(x)*)
 int[x_] := NIntegrate[Cos[t], {t, 0, x}];
 (* create the list of (x1,...,xn) and corresponding list (y1,...,yn)*)
 list1 = Table[-Pi/2 + Pi i/500, {i, 0, 500}];
 list2 = Table[int[-Pi/2 + Pi i/500], {i, 0, 500}];
 (* transpose these lists, this gives x(y) in form of a teble *)
 table = Transpose[{list1, list2}];
 (* original function treated as InterpolatingFunction *)
 eg4direct = Interpolation[table]
interpolate this table to obtain InterpolatingFunction for x(y), that can be used to find D[x(y),y] and so on
eg4inverse = Interpolation[Transpose[{eg4direct[[4]][[3]], eg4direct[[3]][[1]]}]]
(* compare analytic and numeric results *)
Plot[{Abs[(eg4inverse[t] - ArcSin[t])/ArcSin[t]]}, {t, -1, 1},
PlotRange -> Automatic, GridLines -> Automatic]
Note, that you can control InterpolatingFunction props with args for Interpolation
Also, an alternative (more accurate at the ends, but reques y(x) to explicitly defined, not as InterpolatingFunction ) approach was discussed here.
Please consider changing the topic label, so people can re-use it.

POSTED BY: Ivan Morozov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract