1

I have the following problem. I am modelling a cycle that consist of "loading" and "unloading" parts.

Firstly, the material is being loaded from the origin on the "blue line", that is the simple linear function ( $y = 2x$ ), and then I would like to perform transition to the bottom orange line that represents "unloading" of the material (now it is the linear function $y = x$ ):

linear functions as "envelopes"

I created the following solution based just on the ratios of the linear coefficients,

1st sollution:

but it is not accurate enough. I would like to have steeper transition between the blue and orange line. I tried to use $tanh$ function as suggested here but in my situation there is a jump between linear functions and I do not know how to overcome it.

Please, do you have any advices?

Thank you very much in advance!

EDIT:

I would like to get a curve, that comes from the origin to the point $[1;2]$, then I need some transition from the upper line to the bottom line (that I need to be steep enough, using hyperbolic tangens?) and from the point that is as close as possible to the point $[1;1]$ on the bottom line go back on the curve to the origin.

Actually, I have a solution (it is my black curve), but it is not precise enought. I would like to kindly ask if anybody knows some improvement of the transition...

my solution

Andrei
  • 37,370
derdin1
  • 11
  • So what you want is a function that approximates $y=x$ up to some close neighborhood of $(1,1)$, then suddenly jump to $(1,2)$. Did I get this right? Also, any restrictions? Such as, can I make my function piecewise linear? Or do you want some smooth function. How should the function behave around $(1,2)$? – Andrei Dec 28 '20 at 22:30
  • Yes, exactly. I would prefer the function to be smooth since I need it in the subsequent differential equations. I was wondering about using tanh in a similar way how it is done here but I am struggling with dealing the jump between the lines...Many thanks for your help – derdin1 Dec 28 '20 at 22:44

1 Answers1

1

I will show you how to think about this type of problems. Let's start from $\tanh$ function:$$\tanh x=\frac{e^x-e^{-x}}{e^x+e^{-x}}$$ Notice that this function varies between $-1$ and $1$. I want to change it to vary from $0$ on the negative side. To do that, we add $1$. So $$\tanh x+1=\frac{2e^x}{e^x+e^{-x}}$$ The transition between $0$ and $2$ happens around $x=0$. So if we want the transition to happen at different $x$, you just need to change the variable. In this case replace $x$ with $x-1$. If you want to change the slope to be more steep, multiply $x-1$ with a large number $c$ (say $c=10$).

Now you have two choices to connect the curves. We start smoothly from the lower curve in both cases. You can approach smoothly with the upper curve, or you can just truncate the $\tanh$ function. It seems like in this case you go with the second option. So we choose to truncate our connecting function at $x=1$, where $$\tanh c(x-1)+1=1$$ Then you add to the $y=x$ this function multiplied by the gap between the curves at $x=1$. In this case the gap is $1$.

So the function you have is $$y=x+1\cdot(\tanh 10(x-1)+1)$$

output

Andrei
  • 37,370