Author Topic: Maths: find the number of solutions of an equation in Basic  (Read 2452 times)

0 Members and 1 Guest are viewing this topic.

Offline persalteas

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 231
  • Rating: +44/-4
  • z80 poweeer
    • View Profile
    • Tout-82
Hello,

I am using this code found on TI-Calc to solve equations and inequalities  :thumbsup:

It works very well... excepted that it always ends on an error NO SIGN CHNG, which means that the solve command cannot found another solution.

Code: [Select]
:ClrHome
:Input Str1
:For(I,1,length(Str1
:sub(Str1,I,1→Str0
:If inString("=≠>≥<≤",Str0
:Then
:I→A
:length(Str1→I
:End
:End
:sub(Str1,1,A-1→Y1
:sub(Str1,A+1,length(Str1)-A→Y2
:"Y1-Y2→Y3
:solve(Y3,X,1,{‾300,300→A
:nDeriv(Y3,X,A+E‾3→E
:Output(4,3,A
:4→I
:Disp "
:Goto 4
:Lbl 1
:solve(Y3/(X-A),X,{‾2,2},{‾E3,E3→B
:nDeriv(Y3,X,B+E‾3→E
:Output(5,3,B
:Goto 4
:Lbl 2
:solve(Y3/(X-A)/(X-B),X,{‾E2,E2},{‾E3,E3→C
:nDeriv(Y3,X,C+E‾3→E
:Output(6,3,C
:Goto 4
:Lbl 3
:solve(Y3/(X-A)/(X-B)/(X-C),X,0,{‾E3,E3→D
:nDeriv(Y3,X,D+E‾3→E
:Output(7,3,D
:Lbl 4
:Disp "
:Output(I,1,"X
:Output(I,2,"=
:If Str0="≠
:Output(I,2,"≠
:If Str0=">" or Str0="<
:Then
:Output(I,2,">
:If E<0 and Str0=">" or E>0 and Str0="<
:Output(I,2,"<
:End
:If Str0="≥" or Str0="≤
:Then
:Output(I,2,"≥
:If E<0 and Str0="≥" or E>0 and Str0="≤
:Output(I,2,"≤
:End
:I+1→I
:If I=5
:Goto 1
:If I=6
:Goto 2
:If I=7
:Goto 3
:Pause
:"

When you study how this program works, you can see that it always searches for 4 solutions to any equation, and gives the error if there is less than 4 solutions...

To prevent the error, is there any mean to know how many solutions the equation have  ??? ?
If I could know it at the begining of the program, I could forbid it to search for more solutions... and give errors.

Thank you for your help...


Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Maths: find the number of solutions of an equation in Basic
« Reply #1 on: June 01, 2013, 12:29:48 pm »
When you study how this program works, you can see that it always searches for 4 solutions to any equation, and gives the error if there is less than 4 solutions...
And if there are more than 4, it only returns 4 solutions ?
(I am too lazy to study the code myself, especially since it's been a while since I last coded in Basic).
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline persalteas

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 231
  • Rating: +44/-4
  • z80 poweeer
    • View Profile
    • Tout-82
Re: Maths: find the number of solutions of an equation in Basic
« Reply #2 on: June 01, 2013, 01:23:15 pm »
yes, obviously.


Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Maths: find the number of solutions of an equation in Basic
« Reply #3 on: June 01, 2013, 09:24:34 pm »
Maybe using the exp>list function ?
It returns the list of the different solutions from a "solve" result.
example :
exp>list(solve(x^2=1,x),x)
                     {1,-1}

And so the number of solution you're looking for is dim(the_list)..

EDIT :
Woops !
I thought it was on TI-68k/Nspire.. Sorry it's late. %)
Good luck anyway !
« Last Edit: June 01, 2013, 09:29:54 pm by Loulou 54 »
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline persalteas

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 231
  • Rating: +44/-4
  • z80 poweeer
    • View Profile
    • Tout-82
Re: Maths: find the number of solutions of an equation in Basic
« Reply #4 on: June 04, 2013, 04:20:02 am »
Thank you anyway, but no :P

We should reproduce this feature on a z80...