Author Topic: Nspire basic create functions in a program  (Read 2529 times)

0 Members and 1 Guest are viewing this topic.

Offline kyllopardiun

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 178
  • Rating: +14/-4
  • Kyllopardiun over 2000 results in google.
    • View Profile
    • Kyllo's blog (a blog about poetry, videos and computing)
Nspire basic create functions in a program
« 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.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Nspire basic create functions in a program
« Reply #1 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.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Nspire basic create functions in a program
« Reply #2 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).




Offline kyllopardiun

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 178
  • Rating: +14/-4
  • Kyllopardiun over 2000 results in google.
    • View Profile
    • Kyllo's blog (a blog about poetry, videos and computing)
Re: Nspire basic create functions in a program
« Reply #3 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...

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Nspire basic create functions in a program
« Reply #4 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.




Offline kyllopardiun

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 178
  • Rating: +14/-4
  • Kyllopardiun over 2000 results in google.
    • View Profile
    • Kyllo's blog (a blog about poetry, videos and computing)
Re: Nspire basic create functions in a program
« Reply #5 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

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Nspire basic create functions in a program
« Reply #6 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.




Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: Nspire basic create functions in a program
« Reply #7 on: April 03, 2011, 01:36:56 am »
What, no love for recursion? Oh well, I suppose the 8x models are the same.
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC

Offline Freyaday

  • The One And Only Serial Time Killing Catboy-Capoeirista-Ballerino
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1970
  • Rating: +128/-15
  • I put on my robe and pixel hat...
    • View Profile
Re: Nspire basic create functions in a program
« Reply #8 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
In other news, Frey continues kicking unprecedented levels of ass.
Proud member of LF#N--Lolis For #9678B6 Names


I'm a performer at heart; I stole it last week.
My Artwork!

Offline kyllopardiun

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 178
  • Rating: +14/-4
  • Kyllopardiun over 2000 results in google.
    • View Profile
    • Kyllo's blog (a blog about poetry, videos and computing)
Re: Nspire basic create functions in a program
« Reply #9 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...
« Last Edit: April 03, 2011, 09:14:18 am by kyllopardiun »

Offline northern_snow

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 132
  • Rating: +17/-1
    • View Profile
Re: Nspire basic create functions in a program
« Reply #10 on: April 07, 2011, 10:52:25 am »
But where is newton2 / newton 3 ... Really not sure where goes wrong.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Nspire basic create functions in a program
« Reply #11 on: April 08, 2011, 11:35:14 am »
Can you define f4 out of the program, or does f3 change every time?

Offline Andre

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 8
  • Rating: +0/-0
    • View Profile
Re: Nspire basic create functions in a program
« Reply #12 on: April 10, 2011, 10:13:50 am »
This is offtopic, but what software you guys use to code?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Nspire basic create functions in a program
« Reply #13 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.




Offline DJ Omnimaga

  • Former TI programmer
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55865
  • Rating: +3151/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: Nspire basic create functions in a program
« Reply #14 on: April 13, 2011, 01:40:50 am »
Nope, no other editor yet. I haven't seen any on TI-BANK either.
In case you are wondering where I went, I left Omni back in 2015 to form CodeWalrus due to various reasons explained back then, but I stopped calc dev in 2016 and am now mostly active on the CW Discord server at https://discord.gg/cuZcfcF



Official Website |T-Shirt store | Reverbnation | Facebook | Youtube | Twitter | Spotify