Hello guys,
Do you know how can I get (or at least show) the results of the app LinReg (ax+b) when embedded in my own program?

For example, I have this program:


Code:
Prompt N
ln(L₂)→L₄
1/L₂→L₃

If (N=­1)
Then
(L₂²-L₂(1)²)→L₅
LinReg(ax+b) L₁,L₅,Y₁
End

If (N=0)
Then
(L₂-L₂(1))→L₅
LinReg(ax+b) L₁,L₅,Y₁
End


The problem is, even though the calculator performs the operations, the results of a, b, r and r2 are not shown. What can I do?

Thanks for your help
I am not exactly sure what r1 and r2 are supposed to represent but to write a program that displays the linear regression ax+b from the lists L1 and L2:


Code:
Prompt L1,L2
LinReg(ax+b) L1,L2


Edit: Note, when prompting a list in TI-BASIC, you manually have to put the brackets around it
I was not trying to prompt lists.
The problem is that LinReg results were not showing up. When you posted your example I compared both of our programs and I realized that the if/then/end was somehow messing with the LinReg function. Try executing the program I posted and you will probably see the issue.

Anyway I got out the LinReg to the end of the program and now everything works fine.
For reference, when you use regression commands in a program rather than on the home screen, the stat variables a, b, r and r² are set, so you could do something like this:

Code:
Prompt N
ln(L₂→L₄
L₂⁻¹→L₃
If (N=­1
(L₂²-L₂(1)²)→L₅
If (N=0
(L₂-L₂(1))→L₅
LinReg(ax+b) L₁,L₅,Y₁
Disp "Slope",a
Disp "Y Intercept",b
Disp "r",r
Disp "r²",r²

(Where a,b,r and r² are the variables from the [VARS]→[Statistics...]→[EQ] menu)
However, if the last line of a program is value-returning, that value gets displayed, which is why when you put the LinReg command at the end of the program, you get everything displayed.
You don't need Then and End if your if statement only has 1 line. You don't need to close quotes and parentheses at the end of lines. I would recommend using L1 and L2 when using regression commands because they are the default, so if you use those, you can just say

Code:
LinReg(ax+b)
instead of
LinReg(ax+b) L₁,L₂,Y₁

I didn't change that because I'm assuming this is part of a bigger program where those variables are already used. Also, your If statements could be done like this:

Code:
If N
(L₂²-L₂(1)²)→L₅
If not(N
(L₂-L₂(1))→L₅

Since non-zero values evaluate to true, but in case you would want to add more formulas, I left that as-is. If you're just using N to determine what formula the user wants to use, I would recommend the menu() command, which will be a lot more intuitive and clean for users.
However, if you want to stick with the current Prompt, assuming N will only take either 1 or 0, if you want to be really fancy, you could do this:

Code:
(L₂²-L₂(1)²)

can be factorized into:

(L₂-L₂(1))(L₂+L₂(1))

so using N to combine the two formulas, you get to replace this:

If N
(L₂²-L₂(1)²)→L₅
If not(N
(L₂-L₂(1))→L₅

with this:

(L₂-L₂(1))(not(N)+N(L₂+L₂(1→L₅
  
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