4

I am looking for such a function for plotting a figure like in the picture in Python.

Many thanks!

enter image description here

Theo Bendit
  • 50,900
Linghui
  • 41
  • What is Python? Are you sure it is the right site? – markvs Feb 04 '22 at 04:17
  • 2
    @markvs Python is an interpreted programming language, with an impressive suite of functions and objects for mathematical computation. We even have a [tag:python] tag for this site. – Theo Bendit Feb 04 '22 at 04:19
  • 1
    @Linghui You could try experimenting with shifting $\arctan(x)$ or $\frac{x}{|x| + 1}$ vertically and horizontally. – Theo Bendit Feb 04 '22 at 04:24
  • @TheoBendit: The OP wants users of Math. SE to write a piece of code for him? What is the context in this question? – markvs Feb 04 '22 at 04:27
  • 2
    @markvs Leaving the (highly dubious) quality of this question out of it, I think the OP wants to use python to produce a graph, which they are capable of doing if they are given an explicit formula. They just want an explicit formula that produces a shape similar to what they've drawn. That is, the question isn't really about python or coding, but the abstract skill of matching formulas to graphs. – Theo Bendit Feb 04 '22 at 04:29
  • Why does (s)he mention Python in it? And not C++ or Basic? Is the purpose to bragg about knowing Python? – markvs Feb 04 '22 at 04:32
  • Perhaps it is because Python is the only language he knows. We all start somewhere! – Scene Feb 04 '22 at 04:34
  • 2
    @markvs I'm glad they mentioned python, simply because it's the one piece of context that this question has. I at least now know the purpose of this question, and it gives me some idea of the "error tolerance" involved. I might have otherwise, based on the title, suggested that the OP try $(1 - x)^3$, or more likely, not suggested anything at all, because I'd have no idea how helpful it'd've been. – Theo Bendit Feb 04 '22 at 04:49
  • @SeanXie: Are you saying that it is possible to know only Python and nothing else? – markvs Feb 04 '22 at 04:58
  • 3
    @markvs I'm not sure dwelling over which language OP uses is helpful at this point. While it would be better if OP could comment to clarify their intentions as to whether they want a smooth function over the whole domain or breaking it into pieces would suffice, I feel it is sufficient to deduce that they intend to use some kind of graphing software to plot it, so an explicit formula that's easy to evaluate is needed. I don't think it's necessary to read further into the "in python" specification. – Elliot Yu Feb 04 '22 at 05:17
  • The question should be closed for lack of content or lack of details or both. I have voted to close. – markvs Feb 04 '22 at 05:24
  • @TheoBendit "the question isn't really about python or coding, but the abstract skill of matching formulas to graphs" Yes, thank you very much! – Linghui Feb 04 '22 at 18:58

3 Answers3

4

You want to craft $f(x)$ so that $f''(x)$ is

  • positive for $0 < x < 1.$
  • $= 0$, for $x = 1.$
  • negative for $1 < x.$

Also, it appears that you want $f(0) = 0.$

Let $g(x) = f''(x)$.

It is easy to construct $g(x) = 1 - x.$

Then, integrating twice, you have that

$$ f(x) = \frac{x^2}{2} - \frac{x^3}{6}.\tag1 $$

Edit

If it is also desired that $f(1)$ take on a certain value $A$, note that in (1) above, you can add the term $rx^1$ to $f(x),$ where $r$ can be any scalar. Such an added term will have no effect on either the second derivative of $f$, or the constraint that $f(0) = 0.$

Edit

In retrospect, given your question's preCalculus tag, I question how appropriate my answer is. However, I was introduced to the concept of convex/concave functions as part of a Calculus class, and I do not know how to approach the problem in any other way.

user2661923
  • 35,619
  • 3
  • 17
  • 39
1

python is able to concatenate functions, right, so why not use two functions, one for the each intervall?

starrin
  • 41
1

Consider

$$y=\arctan(x-1)+\pi/4$$ enter image description here

Golden_Ratio
  • 12,591