Hello! I have this algorithm, and the problem is that the list(L6) doesnt hold it data as it should.

Code:

"+-sin(cos(tan(log(ln(("->Str0
For(I,1,2)
   inString(Str9,sub(Str0,I,1))
   Repeat not(Ans
      If Ans != 0 Then
         Ans -> A:0->P:0->T
         For(J,3,length(Str0))
            sub(Str0,J,1)->Str8
            inString(Str9,Ans,P+1)
            If Ans = 0 or Ans > A Then
               1+T->T:A
            End
            While Ans<A
               inString(Str9,Str8,P+1)
               inString(Str9,")",Ans+1)
               If Ans<A and (inString(Str9,Str8,Ans+1)=0 or inString(Str9,Str8,Ans+1)>A Then
                  1+t->T:A
               Else
                  Ans->P
               End
            End //while
         End //for
         If T = length(Str0)-2 Then
            A ->L6(1+dim(L6)):0->T
         End
      End //If
      inString(Str9,sub(Str0,I,1),A+1)
   End //Repeat
End //For

!= means not eqal to
-> means store

Str9 is function previously converted from Y1 to string.
Basically what this code is doing is its searching for all + and - withint the function that are not within functions in Str0(beginning from position 3). The only thing that isnt working properly is this line:

Code:

A->L6(1+dim(L6))

What its supposed to do is to list plus and minus signs in the order in which they were found, but the result is diffrent. Any ideas?
I think it may be more than just that line. Are you sure A is holding the correct value?
Yes, it is correct, i tested this code on many functions and the results were correct, just not in the order they should be.
Can you explain how this algorithm is supposed to work so we can help you figure out what's not working?
I get back the question, i discovered it doesnt allways give correct answers for some function. I will return when its fixed.

Kerm, it searches Str9(which is the function in Y1) for '+' and '-'. When it finds one, it searches for any occurances of Str0(except + and -, thats why i start the for loop with 3).Unfortunately i have to search for each function separately.

When it finds one of them, it checks if it closes( ')' ) before the position of found '+' or '-'( i will call it A from now on) and if so, it checks if there is any more of those functions before A.

If there is no more occurances or next occurance is after A, A is not within paranthesis(within a function). 1 is added to T.
This code is looped for all the functions. If A is not within any paranthesis T should be equal to length of str0 -2 (plus and minus signs), and then, A is added to the L6 list.

Try it out on a simple function like sin(x) + cos(x+3) * tan(x-10), it should give you 4 instead of all plus and minus signs.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement