Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Function from 0 to 1

Subject: Function from 0 to 1

From: Diego Zegarra

Date: 7 Mar, 2009 17:54:01

Message: 1 of 19

Hey guys, does anyone know any non-linear function that ranges from 0 to 1 where the input to the function is always greater than or equal to 0. When 0 is the input the functions output should be 0.

Thanks!

Subject: Function from 0 to 1

From: Matt

Date: 7 Mar, 2009 18:04:01

Message: 2 of 19

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <goucbp$gbg$1@fred.mathworks.com>...
> Hey guys, does anyone know any non-linear function that ranges from 0 to 1 where the input to the function is always greater than or equal to 0. When 0 is the input the functions output should be 0.
>
> Thanks!

(sin(x)+1)/2

Subject: Function from 0 to 1

From: Matt Fig

Date: 7 Mar, 2009 18:07:01

Message: 3 of 19

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <goucbp$gbg$1@fred.mathworks.com>...
> Hey guys, does anyone know any non-linear function that ranges from 0 to 1 where the input to the function is always greater than or equal to 0. When 0 is the input the functions output should be 0.
>
> Thanks!

f = @(x) abs(sin(x))

Subject: Function from 0 to 1

From: Matt

Date: 7 Mar, 2009 18:08:01

Message: 4 of 19

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <goucbp$gbg$1@fred.mathworks.com>...
> Hey guys, does anyone know any non-linear function that ranges from 0 to 1 where the input to the function is always greater than or equal to 0. When 0 is the input the functions output should be 0.
>
> Thanks!

x*exp(1-x)

Subject: Function from 0 to 1

From: Matt

Date: 7 Mar, 2009 18:09:02

Message: 5 of 19

"Matt " <xys@whatever.com> wrote in message <goucuh$og7$1@fred.mathworks.com>...
> "Diego Zegarra" <diegozbb@gmail.com> wrote in message <goucbp$gbg$1@fred.mathworks.com>...
> > Hey guys, does anyone know any non-linear function that ranges from 0 to 1 where the input to the function is always greater than or equal to 0. When 0 is the input the functions output should be 0.
> >
> > Thanks!
>
> (sin(x)+1)/2

forget it, that doesn't work. The function does not have to be monotonic, right?

Subject: Function from 0 to 1

From: Matt Fig

Date: 7 Mar, 2009 18:17:01

Message: 6 of 19

If you want a non-oscillating function, here is one.

f = @(x) 1 - 1./(x.^2 + 1)


f(0) = 0

lim f(x) = 1
x->Inf

Subject: Function from 0 to 1

From: Matt

Date: 7 Mar, 2009 18:18:01

Message: 7 of 19

"Matt " <xys@whatever.com> wrote in message <goud7u$e5g$1@fred.mathworks.com>...
> "Matt " <xys@whatever.com> wrote in message <goucuh$og7$1@fred.mathworks.com>...
> > "Diego Zegarra" <diegozbb@gmail.com> wrote in message <goucbp$gbg$1@fred.mathworks.com>...
> > > Hey guys, does anyone know any non-linear function that ranges from 0 to 1 where the input to the function is always greater than or equal to 0. When 0 is the input the functions output should be 0.
> > >
> > > Thanks!
> >
> > (sin(x)+1)/2
>
> forget it, that doesn't work. The function does not have to be monotonic, right?

If it does, then

f=@(x) 1-exp(-x)

will do

Subject: Function from 0 to 1

From: Diego Zegarra

Date: 7 Mar, 2009 18:20:02

Message: 8 of 19

What do you mean by monotonic? I need a function that goes from 0 to 1 but as the input gets further from 0, the output is closer to 1.

Subject: Function from 0 to 1

From: Diego Zegarra

Date: 7 Mar, 2009 18:24:01

Message: 9 of 19

Hey Matt thanks yes thats what I need, but i dont seem to be able to get it work. Please show me how to.

Subject: Function from 0 to 1

From: Diego Zegarra

Date: 7 Mar, 2009 18:27:02

Message: 10 of 19

Nevermind Matt I figured it out. However I need one that does not reach 1 that fast, i would like it to reach 1 when the input is about 500 or so. Thanks!

Subject: Function from 0 to 1

From: Diego Zegarra

Date: 7 Mar, 2009 18:36:01

Message: 11 of 19

I need an increasing function that goes from 0 to 1 where it reaches starts increasing slowly at the beginning and with time it goes increasing more and more and then it slows down again. I hope I made myself clear. Kind of like starting with a x^3 graph but when getting close to 1 do the opposite behaviour.

Subject: Function from 0 to 1

From: John D'Errico

Date: 7 Mar, 2009 18:45:03

Message: 12 of 19

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <goucbp$gbg$1@fred.mathworks.com>...
> Hey guys, does anyone know any non-linear function that ranges from 0 to 1 where the input to the function is always greater than or equal to 0. When 0 is the input the functions output should be 0.
>
> Thanks!

Do you mean something that goes through 0 at x = 0,
is strictly monotone increasing, and rises to an asymptote
of f(x) = 1 as x approaches inf?

So many functions will fit the requirements.

Here is one based on an exponential.

  f1 = @(x) -1 + 2./(1+exp(-x))

% Or, use erf. It is much like a cumulative normal.

  f2 = @(x) erf(x)

% An atan has a subtly different shape. See that the
% atan takes much longer to reach the asymptote.

  f3 = @(x) atan(x)*2/pi

% A hyperbolic tangent?

  f4 = @(x) tanh(x)

subplot(2,2,1)
ezplot(f1,[0,3])
subplot(2,2,2)
ezplot(f2,[0,3])
subplot(2,2,3)
ezplot(f3,[0,3])
subplot(2,2,4)
ezplot(f4,[0,3])

One could surely find a few others. Look here for
some ideas about how to shift and scale them
to achieve a specific desired shape.

http://www.mathworks.com/matlabcentral/fileexchange/10864

John

Subject: Function from 0 to 1

From: John D'Errico

Date: 7 Mar, 2009 18:50:03

Message: 13 of 19

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <goueqh$qn$1@fred.mathworks.com>...
> I need an increasing function that goes from 0 to 1 where it reaches starts increasing slowly at the beginning and with time it goes increasing more and more and then it slows down again. I hope I made myself clear. Kind of like starting with a x^3 graph but when getting close to 1 do the opposite behavior.

So you need a function with an inflection point.

A = 5;
f5 = @(x) gammainc(x/50,A);
ezplot(f5,[0,500])

You can vary the shape by changing A.

John

Subject: Function from 0 to 1

From: Justin Abbott

Date: 7 Mar, 2009 18:54:01

Message: 14 of 19

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <goueqh$qn$1@fred.mathworks.com>...
> I need an increasing function that goes from 0 to 1 where it reaches starts increasing slowly at the beginning and with time it goes increasing more and more and then it slows down again. I hope I made myself clear. Kind of like starting with a x^3 graph but when getting close to 1 do the opposite behaviour.

I am not completely sure what you mean, but I think what you are saying is that over an interval from 0 to k you want the graph to be concave up and from k on you want it to be concave down. In this case x = k is called an inflection point.

You can try

f = @(x) 1 - 1./(1+alfa.*x.^2)

The parameter alfa allows you to control how quickly it approaches 1. If for a given value x0 you want |1-f(x0)|<=err then alfa is given by

alfa = (1-err)./(err.*x0.^2)

HTH,
Justin

Subject: Function from 0 to 1

From: John D'Errico

Date: 7 Mar, 2009 19:00:04

Message: 15 of 19

"Justin Abbott" <abbottjj@NOPSAM.saic.com> wrote in message <goufs9$aeo$1@fred.mathworks.com>...
> "Diego Zegarra" <diegozbb@gmail.com> wrote in message <goueqh$qn$1@fred.mathworks.com>...
> > I need an increasing function that goes from 0 to 1 where it reaches starts increasing slowly at the beginning and with time it goes increasing more and more and then it slows down again. I hope I made myself clear. Kind of like starting with a x^3 graph but when getting close to 1 do the opposite behaviour.
>
> I am not completely sure what you mean, but I think what you are saying is that over an interval from 0 to k you want the graph to be concave up and from k on you want it to be concave down. In this case x = k is called an inflection point.
>
> You can try
>
> f = @(x) 1 - 1./(1+alfa.*x.^2)
>
> The parameter alfa allows you to control how quickly it approaches 1. If for a given


A good idea, but this actually has no inflection point
on the interval [0,inf].

John

Subject: Function from 0 to 1

From: Diego Zegarra

Date: 7 Mar, 2009 19:03:02

Message: 16 of 19

Thanks John that gammainc was exactly the shape I was looking for!

Subject: Function from 0 to 1

From: Justin Abbott

Date: 7 Mar, 2009 19:30:04

Message: 17 of 19

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <goug7k$47k$1@fred.mathworks.com>...
> "Justin Abbott" <abbottjj@NOPSAM.saic.com> wrote in message <goufs9$aeo$1@fred.mathworks.com>...
> > "Diego Zegarra" <diegozbb@gmail.com> wrote in message <goueqh$qn$1@fred.mathworks.com>...
> > > I need an increasing function that goes from 0 to 1 where it reaches starts increasing slowly at the beginning and with time it goes increasing more and more and then it slows down again. I hope I made myself clear. Kind of like starting with a x^3 graph but when getting close to 1 do the opposite behaviour.
> >
> > I am not completely sure what you mean, but I think what you are saying is that over an interval from 0 to k you want the graph to be concave up and from k on you want it to be concave down. In this case x = k is called an inflection point.
> >
> > You can try
> >
> > f = @(x) 1 - 1./(1+alfa.*x.^2)
> >
> > The parameter alfa allows you to control how quickly it approaches 1. If for a given
>
>
> A good idea, but this actually has no inflection point
> on the interval [0,inf].
>
> John

I tried to post this a minute ago but received a network error message, so I apologize for double posting if the other one goes through.

John -

Your comment through me for a bit of a loop because I had plotted the curve and can see what appears to be a change in the concavity, so I took some derivatives and am back with a question.

If I set alfa = 1, then for the zeros of f' and f'' I get
f'=0 => x = 0
f''=0 => x = 0, +/-sqrt(3)

My memory is that an inflection point occurs when both 1st and 2nd derivates are zero and the second derivative changes sign; so x^4 doesn't have one at x=0.

However, since I don't have a Calculus book handy at the moment, I went an looked at wikipedia.
http://en.wikipedia.org/wiki/Inflection_point

This page says:
"Points of inflection can also be categorised according to whether f'(x) is zero or not zero.
-if f'(x) is zero, the point is a stationary point of inflection, also known as a saddle-point
-if f'(x) is not zero, the point is a non-stationary point of inflection

Were you getting at the fact that the only zero of the f' is at x=0?

-Justin

Subject: Function from 0 to 1

From: Matt Fig

Date: 7 Mar, 2009 19:56:01

Message: 18 of 19

Why is 1/sqrt(3*alpha) not an inflection point? Maybe my calculus is rusty.

Subject: Function from 0 to 1

From: John D'Errico

Date: 7 Mar, 2009 20:09:01

Message: 19 of 19

"Justin Abbott" <abbottjj@NOPSAM.saic.com> wrote in message <gouhvs$sbs$1@fred.mathworks.com>...

> Your comment through me for a bit of a loop because I had plotted the curve and can see what appears to be a change in the concavity, so I took some derivatives and am back with a question.
>

Sorry, I was too quick. This does have an inflection
point.

John

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us