Page 1 of 1

if function in graph

Unread postPosted: 15 Dec 2012, 09:32
by sportler1993
Hello
I search a programm witch can split a graph in 3spaces
Perhaps If X<=2 Y=2X
If 10<X>2 Y=5x
If X>=10 Y=50

Is there any possibility to make this :help:

Re: if function in graph

Unread postPosted: 15 Dec 2012, 09:49
by Levak
Hi,
You can directly do it in a function on TI-Nspire :
Code: Select all
: Define myfunc(x) = Func
:   If x <= 2
:     Return 2*x
:   If x > 2 and x < 10
:     Return 5*x
:   Return 50
: EndFunc


and draw the function f1(x) = myfunc(x) in a Graph page.

Re: if function in graph

Unread postPosted: 15 Dec 2012, 16:39
by sportler1993
Thanks
But i dont know where i should enter this code?
Thanks for help

Re: if function in graph

Unread postPosted: 15 Dec 2012, 16:42
by Bisam
You can also use the function "when" or better, the "piecewise template", that is the left bracket { with 4 spaces 2 by 2 separated by commas.

The syntax for the piecewise template is :
Code: Select all
{ 2x , x<=2
{ 5x , x>2 and x<10
{ 50 , x>=10

where the left brackets should be only one bracket on you calc.

The one for "when" is :
Code: Select all
when(x<=2, 2x, when(x<10, 5x,50))



If you use Levak's method, you should create a "function" using the editor on calc.

if function in graph

Unread postPosted: 21 Jan 2013, 21:47
by sportler1993
Whiy this code dont work?
How can i define a?

Code: Select all
: Define myfunc(x) = Func
:   a=2x
:   If a <= 2
:     Return 2*x
:   If a > 2 and a < 10
:     Return 5*x
:   Return 50
: EndFunc

Re: if function in graph

Unread postPosted: 21 Jan 2013, 22:03
by Excale
a:=2x and Endif :).

Re: if function in graph

Unread postPosted: 22 Jan 2013, 03:04
by Levak
Hi
You also should use "Local a" at the beginning of the functiin since in a Func (contrary to a Prgm) you cannot modify the external variables.

Re: if function in graph

Unread postPosted: 22 Jan 2013, 09:43
by Bisam
The "Endif" is not necessary : there is no "Then".
Is is useless when there is only one instruction after "If".

As for the "Local", you HAVE TO use it in a function.