If you don't know, Demoivre's Theorem is a way to find out the powers of complex number, such as (1+i)^5.

Right now, I am having trouble with a variable not stopping. Here is the code for my program. By the way, I will be editing the code to match the corrections when they become available.
Code:
```ClrHome 1->P 1->Q 1->R 1->S Disp "(a+bi)^n" Input "a: ",A Input "b: ",B Input "n: ",N If abs(A/S)=1 and abs(B/S)=1 Goto C Lbl S If A/S<=1 and A/S>=~1 Then If B/S<=1 and B/S>=~1 Then Goto B Else Goto C End Else Goto C End End Lbl C If Q=1 Then ~Q->Q sqrt(2)P->P P->S Goto S End If Q=~1 Then ~Q->Q 2+R->R R->S Goto S End Lbl B cos^-1(A/S)->C sin^-1(B/S)->D C/5->G D/5->H If iPart(G)!=G and iPart(H)!=H Goto C If A<0 and B>0 180-D->D If A<0 and B<0 Then 360-C->C 180-D->D End If A>0 and B<0 ~C->C cos(NC)->E sin(ND)->F If fPart(F)=~2|E~13 or fPart(F)=~4|E~13 iPart(F)->F (S^N)(E+Fi)->E ClrHome Output(1,1," The Answer Is: ") Output(2,1,E) Pause ClrHome Output(1,1,"")```
First problem: This line doesn't do what you think it does.
Code:
`If A/S=1 or ~1 and B/S=1 or ~1 `
Check out my correction to see the steps of fixing it:
Code:
```If A/S=1 or A/S=~1 and B/S=1 or B/S=~1  // sort of correct If (A/S=1 or A/S=~1) and (B/S=1 or B/S=~1) // definitely correct If abs(A/S)=1 and abs(B/S)=1 // even better```
I will try that then, but what did it do?
Well, in TI-BASIC, you cannot chain commands like most other programming languages.

If A=1 or -1

means

If A=1 or If -1; Which will always be true. You have to specify each variable as you check it.
MrDew25 wrote:
I will try that then, but what did it do?
In conditional expressions (see chapter 3 of my awesome and shamelessly-plugged book), any zero value is equivalent to false and any non-zero is equivalent to true. The calculator reads that line as: If <something> or true and <something> or true, because -1 is nonzero and therefore true. Thus, that line is always true and always runs the following Goto command. The " or " command is not for specifying options to the = sign, but for specifying sets of conditions, any one of which can be true to make the whole expression true.
I think that the problem lies somewhere inside Label C. Correct me if I am wrong.
Separate from any other issue, I notice you Goto from inside a Then/End block, which is a memory leak and to be avoided. You should restructure your code so that any conditional Gotos are just If/Goto, never If/Then/Goto/End. Anyway, it would probably help if you told us a little bit about what the algorithm is supposed to be and what the code at Lbl B, C, and so on is supposed to do.
Would a If/Then/Goto/Else/Goto work?
Lbl C is the main label. As the theorem takes complex number raised to a power, (1+i)^5, and changes them into their trigonometrical form, which is r^n(cosnθ + isinnθ) (r is the radius, n is the power and θ is the angle). In our case, it is sqrt(2)^5(cos5θ + isin5θ) Lbl C finds the radius. Lbl B finds the angle and then puts everything together.
Ok, I edited the issue that you talked about Kerm to this
Code:
```Lbl S If A/S<=1 and A/S>=~1 Goto D Lbl D If B/S<=1 and B/S>=~1 Goto B If A/S>1 or A/S<~1 Goto C If B/S>1 or B/S<~1 Goto C```
Okay, here's my attempt: (Not sure if this is right or not, but here it goes:)

Code:
```ClrHome Disp "(A+B[i])^N Prompt A,B,N Fix 3 tan^-1(B/A (sqrt(A^^2+B^^2)^N)(cos(Ans)+[i]sin(Ans```

Does this work right for you? (Probably doesn't; I need some example problems to check it really quick...)

EDIT: Nope, doesn't work... Let's see where I went wrong...

EDIT: WHY?
The code worked. The code I used was
Code:
```ClrHome Disp "(A+B[i])^N Input "A: ",A Input "B: ",B Input "N: ",N tan^-1(B/A)->C (sqrt(A^^2+B^^2)^N)(cos(NC)+[i]sin(NC)```
which came from you. Great job
MrDew25 wrote:
Would a If/Then/Goto/Else/Goto work?
No, that's still a Goto inside a Then/End, and has the same memory leak problems. Also, please do not double-post, and definitely do not triple-post. I recommend you read A Brief Introduction to Better Netiquette.
Sorry, I haven't been a forum in a while.

EDIT: And ok, I understand. See, I am a fast learner.
MrDew25 wrote:
The code worked. The code I used was
Code:
```ClrHome Disp "(A+B[i])^N Input "A: ",A Input "B: ",B Input "N: ",N tan^-1(B/A)->C (sqrt(A^^2+B^^2)^N)(cos(NC)+[i]sin(NC)```
which came from you. Great job

Oh wow, thanks! Knew I was forgetting something important... Those pesky N's!

Also, here's a really optimized piece:

Code:
```ClrHome Disp "(A+B[i])^N Prompt A,B,N Ntan^-1(B/A (sqrt(A^^2+B^^2)^N)(cos(Ans)+[i]sin(Ans```

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.

»
» 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