0

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))
Manipulate[Plot[f[a,x],{x,0,a}],{a,0,20,0.05}]

which doesn't work...

Banalaude
  • 107
  • 4
  • 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. – bbgodfrey Jul 19 '21 at 18:10

1 Answers1

2

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}]
Domen
  • 23,608
  • 1
  • 27
  • 45
  • 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...). – Banalaude Jul 20 '21 at 04:23
  • 1
    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"}] – Domen Jul 20 '21 at 09:51