0
$\begingroup$

I have a function $f(x)$ that takes some time to evaluate. It's straightforward to plot but I'd also like to plot it as a function of y where, let's say, $y=\sin(x)$.

When I try Plot[f[Sin[x]],{Sin[x],lowlim,hilim}] Mathematica re-evaluates the function with the argument $\sin(x)$, which takes a while and doesn't give the right answer anyway. (The limits are right at least!)

Other things I've tried: With[{y=Sin[x]},Plot[f[y],{y,lolim,hilim}]] but I get the Tag Protected error. The slash dot rule /.y->Sin[x] yielded nothing. I also tried Block[{y=Sin[x]},Plot[f[y],{etc}]] and I get the raw object can't be used as an iterator error.

I'm sure the solution must be really simple but I just haven't found it myself yet. Essentially, I just want to scale the dependent variable axis without re-evaluating the function.

$\endgroup$
6
  • 1
    $\begingroup$ The simplest way is making a list of values of the function first (using Table for example) and, further, plot it by ListPlot. So, you can re-run the plotting routing for some correction of the curve view without re-evaluation of the function. $\endgroup$
    – Rom38
    Aug 28 '20 at 10:00
  • $\begingroup$ Plot[f[Sin[x]],{x,xLowlim,xHilim}]. You need to set the limits for x since this is what you are integrating over. $\endgroup$
    – Natas
    Aug 28 '20 at 12:14
  • $\begingroup$ Of course in your case the x limits won't be unique, i guess {x, ArcSin[lowlim], ArcSin[hilim]} gives you an idea of the problem... $\endgroup$
    – Natas
    Aug 28 '20 at 12:20
  • 1
    $\begingroup$ 1) Tabulate f[x], 2) Interpolate the data fi[x], 3) plot fi[sin[x]]. $\endgroup$
    – yarchik
    Aug 28 '20 at 13:43
  • $\begingroup$ @Rom38 @ yarchik Yes, I was resisting making a table of values and working with that because I like that generally Mathematica doesn't make you deal with discrete values. But none of the other suggestions work so far - the original function is always re-evaluated and yields the wrong answer. So it looks like tabulating is the way to go this time. $\endgroup$
    – netto
    Aug 31 '20 at 6:10
2
$\begingroup$

It is OK or not?

 f[x_] := x^2;
Plot[f[x], {x, -.5, .5}]
Plot[f[Sin[x]], Element[x, ImplicitRegion[-.5 <= Sin[x] <= .5, x]]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Plot[{f[x], f[Sin[x]]}, {x, -Pi, Pi}, PlotRange -> {0, 1}, PlotLegends -> "Expressions"] $\endgroup$
    – Bob Hanlon
    Aug 28 '20 at 17:21
1
$\begingroup$

I found a slightly ugly solution, and perhaps someone can suggest a more elegant way!

Instead of writing $ f(x)$ as a function f[x], I wrote it as a variable f then assigned a new function g[x]=f. Then I plotted Plot[g[x=ArcSin[y]],{y,ylolim,yhilim}]

What that works and Plot[f[x=ArcSin[y]],... does not isn't totally clear to me, but I think it's because f[x] is not being recalculated.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.