I know similar questions have been asked, but I am very new at Mathematica and other questions/answers are quite complex and do not suit the code I want to write.

I want to restrict the domain of the function f(x) to be between 0 and a, for the variable x. (I do not want to restrict the plot, just the function - just as in this question). f[x_] := x*(1+a*ln(1-x/a)) , where a is a parameter, that I wish to vary from 0 to let's say 20 with increments of 0.05 for instance.

Then, I wish to plot the function with a slider for this a parameter, that is being able to vary it (hence the plot of f(x) - and its domain - adjusting dynamically).

Following the best answer here, I have tried this:

f[a_Real,x_Real]:= x*(1+a*ln(1-x/a))

which doesn't work...

  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Jul 19 at 18:10

The problem: ln(...) should be Log[...]. Furthermore, the endpoints in Plot should be different, so you cannot use a = 0.

f[a_Real, x_Real] := x*(1 + a*Log[1 - x/a])
Manipulate[Plot[f[a, x], {x, 0, a}], {a, 0.05, 20, 0.05}]
  • $\begingroup$ Thank you! Is there a way to also display the value of "a" on the graph, above the slider, or somewhere? When using the slider, I do not know know clearly what the value of "a" is (except observing the last x value on the axis...). $\endgroup$
    – Banalaude
    Jul 20 at 4:23
  • 1
    $\begingroup$ You can click on the "+" button next to the slider. Or you can use Manipulate[Plot[f[a, x], {x, 0, a}], {a, 0.05, 20, 0.05, Appearance -> "Labeled"}] $\endgroup$
    – Domen
    Jul 20 at 9:51

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.