Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: kyllopardiun on April 02, 2011, 03:54:15 pm

Title: Nspire basic create functions in a program
Post by: kyllopardiun on April 02, 2011, 03:54:15 pm
I know it hasn't been a long time since my last post, but
as this is another subject I thought it was better to make a new one...

I was trying to make define a function again, for dont have many functions in the calculator
but I got this error: "To many recursions", and display "Define f2(x)=((f2(x))/(x-raiz))"
Code: [Select]
:        If a≠grau Then
:             Define f2(x)=((f2(x))/(x-raiz))

Now I was wondering if is possible to create functions like f3 ... on demand like
Define f(x)=x...


Thanks, for any help regarding this.
Title: Re: Nspire basic create functions in a program
Post by: Munchor on April 02, 2011, 03:59:15 pm
For all of you who don't know portuguese, raiz=root and grau=degree.

Concerning your question, this is TI-Basic for the 8x series right?
I know the ':' are there, but the syntax reminds me of NSpire.
Title: Re: Nspire basic create functions in a program
Post by: Deep Toaster on April 02, 2011, 04:03:43 pm
No, this is Nspire BASIC. It's more similar to 89 BASIC than to 83 BASIC.

As for your question, you can't define a function to call itself (since that would end in an infinite recursion, which would be bad).
Title: Re: Nspire basic create functions in a program
Post by: kyllopardiun on April 02, 2011, 04:06:21 pm
Is for the nspire, I don't thing the raiz=root may help any as what I need
is to define multiple functions

such as
f1(x)
f2(x)
f3(x)
...
fn(x)

And I can't figure a way to do it...
Title: Re: Nspire basic create functions in a program
Post by: Deep Toaster on April 02, 2011, 04:23:45 pm
Oh, I see. I don't think you can do that, unfortunately. You can always overwrite existing functions though. Don't know if that would help with what you're doing.
Title: Re: Nspire basic create functions in a program
Post by: kyllopardiun on April 02, 2011, 11:57:26 pm
Oh, I see. I don't think you can do that, unfortunately. You can always overwrite existing functions though. Don't know if that would help with what you're doing.

It might help, but how can I overwrite and/or create functions since Define doesn't work?
//it doesn't appear as a syntax error but it don't work
Title: Re: Nspire basic create functions in a program
Post by: Deep Toaster on April 03, 2011, 12:41:53 am
You mean the error you got? That's because you're defining a function that calls itself. You can't do that.
Title: Re: Nspire basic create functions in a program
Post by: DrDnar on April 03, 2011, 01:36:56 am
What, no love for recursion? Oh well, I suppose the 8x models are the same.
Title: Re: Nspire basic create functions in a program
Post by: Freyaday on April 03, 2011, 03:29:41 am
Well, if allowed, the calc would keep computing the func forever because the func says to compute the func again to get a value, so it computes the func again to get a value, but the func says to compute the func again to get a value, so it computes th
OUT OF MEMORY
Title: Re: Nspire basic create functions in a program
Post by: kyllopardiun on April 03, 2011, 09:09:59 am
You mean the error you got? That's because you're defining a function that calls itself. You can't do that.
No I mean when I tried:

Define f3(x)=f2(x)/(x-root)

It doesn't appear as error, but it don't work

I will post the code, so you can understand it better:

Main function:
Code: [Select]
Define vieta(number,grade)=
Prgm
:Local a,root
:   Disp "The root are:"
:   For a,0,grau,1
:    If grade=1 Then
:        root=newton2(number,15)
:        Disp root
:    Else
:       If grade=2 Then
:             newton3(number+a,15,root)→root
:            Disp root
:       Else
:              If grau=3 Then
©-----------------------------------------------------------------------
©Here is where it's showed as the error when I run the "program"
:                    newton4(number+a,15,root)→root
©-----------------------------------------------------------------------
:                   Disp root
:               EndIf
:       EndIf
:    EndIf
:   EndFor
:EndPrgm
In the bold line I get this error: variable not defined

Newton(x)

Code: [Select]
Define newton4(guess,number,root)=
Func
:Local new_guess,fn,k,newt
©-----------------------------------------------------------------------
©Here is the problem....
:Define f4(x)=((f3(x))/(x-root))
©This line doesn't work at all
©-----------------------------------------------------------------------
:newt:={guess}
:For k,1,number
:  new_guess:=guess-((f4(guess))/(nDeriv(f4(x),x=guess)))
:  guess:=new_guess
:  newt:=augment(newt,{new_guess})
:EndFor
:Return new_guess
:EndFunc

Note: newton4() is the same of newton3 which didn't any errors,
and If I call f2()/f3()/f4() they are not defined...
Title: Re: Nspire basic create functions in a program
Post by: northern_snow on April 07, 2011, 10:52:25 am
But where is newton2 / newton 3 ... Really not sure where goes wrong.
Title: Re: Nspire basic create functions in a program
Post by: fb39ca4 on April 08, 2011, 11:35:14 am
Can you define f4 out of the program, or does f3 change every time?
Title: Re: Nspire basic create functions in a program
Post by: Andre on April 10, 2011, 10:13:50 am
This is offtopic, but what software you guys use to code?
Title: Re: Nspire basic create functions in a program
Post by: Deep Toaster on April 10, 2011, 11:57:37 am
Probably the built-in program editor on the Nspire. There aren't any off-calc editors for Nspire BASIC yet, I think.
Title: Re: Nspire basic create functions in a program
Post by: DJ Omnimaga on April 13, 2011, 01:40:50 am
Nope, no other editor yet. I haven't seen any on TI-BANK either.