Author 
Message 

Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565

Posted: 20 Feb 2009 04:12:49 pm Post subject: 


Well I hope we can get nice routines here. I did them essentially at math classes or in home to somewhat help me. (and have good, healthy but odd fun)
First, I have to say that most of the code posted is made by me and if someone made before is pure coincidence. I am not going to search for it every time I want to post something. Note: that I use some Weregoose routines to do some work or he as already shared them as very optimized so no need to make them. Just note that you, Weregoose, have a great work! All thanks given to him in his part.
I have classes in my mother language so I will need help to translation of all mathematical terms. I will help with giving their proper description (as much as I can). Where I have doubts I will put an "(?)". Sorry about missing translations... But I will try t make the needed.
Now the fun part:
Test functions parity: (?) (means if it is symmetric with X or Y axis. EVEN (?), ODD (?) I don't remember right, too lazy to see last year math book)
[quote name='"BASIC Code"']:" PARITY→Str9
:Disp "",Ans,"
:Input "F(X)=",Str0
:Str0→Y0
:ClrHome
:Disp Str9
:" FUNCAO
:Disp Ans,Ans
:seq(X,X,‾10,10,.6→L6
:Y0(‾Ans→L5 \\ yeah, nice trick...
:Y0(L6
:If min(Ans=L5
:Output(2,9,"EVEN
:If min(‾Ans=L5
:Output(3,9,"ODD
:End[/quote]
Not extensively tested but can't stop working great at my tests. Danger with undefined (?) (when function has no meaning in IR) part of function.
Sorry about some string compression with Str9... And as history: the first version of this was very slow (30 seconds running), then in a math class discovered the Y1(list trick and with my new experience coding could improve much more!
Test function monotonicity: (if function increases/decreases in y)
[quote name='"BASIC Code"']:Disp " MONOTONIA
:Input "F(X)=",Str0
:Str0→Y0
:Input "LEFT=",A
:Input "RIGHT=",B
:Input "PRECISION=",I
:0≤DeltaList(Y3(seq(X,X,A,B,I→L6 \\same trick as above ^^
:dim(Ans→L
:For(θ,1,L \\ incomplete output
:If L6(θ
:Then
:Disp "STARTS DECREASING IN",BθI
:Else
:Disp "INCREASES...
:End
:End[/quote]
This is a mere sketch of it. I will add full friendly output later. And not extensively tested. Danger with undefined (?) (when function has no meaning in IR) part of function.
Also I could increase speed by a normal step in seq() of 1 and after going deeper on the function to see exactly where... Maybe later release.
Smallest way to test if a vector is collinear (?) (is like the 2 vectors are multiple for each other)
[quote name='"BASIC Code"']:Disp " COLINEAR
:Disp "
:Input "u=",L5
:Input "v=",L6
:" NON COLLINEAR
:If min(L6=L5sum(L6)/sum(L5
:" COLLINEAR
:Disp Ans
:End[/quote]
Note: smells a Brain Teaser, doesn't it? Danger with divisions with 0. Mine doesn't seem to have this problem, it was tested.
All BASIC code Generated by SourceCoder, © 2005 Cemetech
Be critic with my programs, I am not a mathematician or always right. I am just in school, so...
Ok, now cry and wait for more. Good use and please give me feedback!
PS: I have many more in distinct things. Just shown the most interesting or what I really liked.
EDIT: better understanding
thanks thornahawk for the first strange translation.
Last edited by Guest on 20 Feb 2009 04:42:50 pm; edited 1 time in total 

Back to top 


Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565


Back to top 


Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565

Posted: 20 Feb 2009 04:14:07 pm Post subject: 


also reserved. Is enough of reservations. :blush: 

Back to top 


thornahawk μολών λαβέ
Active Member
Joined: 27 Mar 2005 Posts: 569

Posted: 20 Feb 2009 09:36:08 pm Post subject: 


Some comments:
1. With your parity (yes, the terms are even and odd. ) tester, it looks like a function sampling test. You might want to provide for an option to sample the grid more finely, and on a wider range, if needed. It goes without saying that there will always be functions that can fool the routine, but it will work in most cases. :)
2. With the collinearity test, you might want to add a check that the two input vectors have the same dimensions first before employing this formula:
abs(sum(L₅L₆))=√(sum(L₅²)sum(L₆²))
(from here)
That's all I can think of for now.
thornahawk
Last edited by Guest on 20 Feb 2009 09:38:40 pm; edited 1 time in total 

Back to top 


DarkerLine ceci n'est pas une 
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328

Posted: 20 Feb 2009 10:15:34 pm Post subject: 


For collinearity, check if the two lists have the same length, perform 2Var Stats on the lists, then check if Σxy^{2}=Σx^{2}Σy^{2} (some clarification is necessary: the first ^{2} is typed in as usual, the second and third are part of the token)  this is Thornahawk's formula rewritten, more or less.
Last edited by Guest on 11 Jul 2010 06:20:23 pm; edited 1 time in total 

Back to top 


Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565

Posted: 21 Feb 2009 04:54:45 am Post subject: 


ok. It is quite dumb that someone inputs 2 vectors with different length... Anyway I will put a check.
And the idea of the collinear vectors is to have the smallest routine. Mine is 4 bytes less, and works. Does fail in some inputs?
In the parity, I forgot to say the increment is to avoid when a rational function has a division 0:0, that normally happens in integer numbers... Saying this, .6 increments meets some integer values like 3... :/ Well avoids most of them.
I could add input for the range of testing, but that is not perfect for inexperienced.
I have this statistics routine with one risky optimization:
err, this is a linear correlation coefficient. (sees how close is the data to the linear regression, output from 1 to 1, if I remember right) In Portuguese the words are in reverse order...
[quote name='"BASIC Code"']:Disp "COEF CORRELECCAO
:Disp " LINEAR
:Disp "
:Input "∟X=",L1
:Input "∟Y=",L2
:If dim(L1)≠dim(L2
:Goto E
:TwoVar L1,L2
:Disp sum((L1)(L2[yhat]))/(√(sum((L1)²))√(sum((L2[yhat])²
:Pause
:Return
:Lbl E
:Disp "
:Pause " ERROR
:Return[/quote]
This was made last year. I think I cut out an parentheses somewhere and seems fine without it. Maybe added again... It is shared.
Well, I tried to translate but today, is a very bad day for that. :S
[quote name='"BASIC Code"']:Disp " DESVIOMEDIO
:Disp "
:Input "∟DADOS=",L1
:Input "∟FREQ=",Str0
:DelVar S
:If inString(Str0,"{
:Then
:Str0→L2
:Else
:0L1+1→L2
:End
:If dim(L1)≠dim(L2
:Goto E
:Disp sum(L2abs(L1(sum(L1)/dim(L1)))/dim(L2►Frac[/quote]
[quote name='"BASIC Code"']:Disp " AMPLITUDE:
:Disp "
:Input "∟DADOS=",L1
:Input "∟FREQ=",Str0
:OneVar
:If inString(Str0,"{
:Then
:Str0→L2
:If dim(L1)≠dim(L2
:Goto E
:OneVar L1,L2
:End
:ClrHome
:Disp "
:Disp " AMPLITUDE=
:Disp maxXminX
:Disp " INTERQUARTIS=
:Disp Q3Q1[/quote]
And if you find some End at the end is normal. All this snippets of code where cut from inside a If Then... 

Back to top 


thornahawk μολών λαβέ
Active Member
Joined: 27 Mar 2005 Posts: 569

Posted: 21 Feb 2009 07:43:54 am Post subject: 


"ok. It is quite dumb that someone inputs 2 vectors with different length... Anyway I will put a check."
Dumb indeed to us, but what about the user? Consider it "defensive programming". Foolproofing is always a good thing to do for programs!
"And the idea of the collinear vectors is to have the smallest routine. Mine is 4 bytes less, and works. Does fail in some inputs?"
A very trivial case: {1,1,0} and {2,2,0} . :)
"In the parity, I forgot to say the increment is to avoid when a rational function has a division 0:0, that normally happens in integer numbers... Saying this, .6 increments meets some integer values like 3... :/ Well avoids most of them.
I could add input for the range of testing, but that is not perfect for inexperienced."
No need to ask for range input; it's usually convenient to just take whatever is the value of Xmin and Xmax, assuming they are at an equal distance from the origin. But do include a provision to use a finer increment. :)
(edit: on further musing, maybe whatever is the setting for Xres in the calculator would be a good default increment)
For the correlation coefficient, DiagnosticOn ensures that the correlation coefficient is computed and stored when one does a linear regression. (But you knew that already, right? )
I'm not too sure what the second routine does, but I do know you can replace sum(list)/dim(list) with mean(list), per the definition of the mean. Finally, there should be an expr(Str0) before storing to the list.
And for the third program, what you have termed the "amplitude" is called the "range" or "sample range" in English. "INTERQUARTIS" I suppose is meant to refer to the "interquartile range".
thornahawk
Last edited by Guest on 21 Feb 2009 09:48:08 am; edited 1 time in total 

Back to top 


Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565

Posted: 25 Feb 2009 06:03:30 pm Post subject: 


thornahawk wrote: Dumb indeed to us, but what about the user? Consider it "defensive programming". Foolproofing is always a good thing to do for programs! Well in a calculator with so few RAM every byte saved is good. But still a good advice for programming. :)
thornahawk wrote: "And the idea of the collinear vectors is to have the smallest routine. Mine is 4 bytes less, and works. Does fail in some inputs?"
A very trivial case: {1,1,0} and {2,2,0} . ugh, I didn't catch it.
thornahawk wrote: No need to ask for range input; it's usually convenient to just take whatever is the value of Xmin and Xmax, assuming they are at an equal distance from the origin. But do include a provision to use a finer increment. :)
(edit: on further musing, maybe whatever is the setting for Xres in the calculator would be a good default increment) If we assume the person has graphed it, is a good idea. And I don't agree with Xres... It is always between 1 and 8 and an integer I think.
Oh and I made one quick program, in order to see that an increment of 0.9 will avoid much more integer numbers than 0.6. ^^
thornahawk wrote: For the correlation coefficient, DiagnosticOn ensures that the correlation coefficient is computed and stored when one does a linear regression. (But you knew that already, right? ) Well, recently yes but at the time I didn't know and I forgot that detail before posting.
thornahawk wrote: I'm not too sure what the second routine does, but I do know you can replace sum( list)/dim( list) with mean( list), per the definition of the mean. Finally, there should be an expr(Str0) before storing to the list. This weekend I saw that expr( issue. But my calculator runs just fine Str0>L1 but with only small inconvenient: Ans will be the string and not the list. ^^ Anyway I will just, for the case that doesn't work on older Oes or so...
thornahawk wrote: And for the third program, what you have termed the "amplitude" is called the "range" or "sample range" in English. "INTERQUARTIS" I suppose is meant to refer to the "interquartile range".
thornahawk Yes, "interquartis" are related to range, so it must be it.
This holidays I worked on the math programs and shaved some bytes, added more things... It was a nice progress. My calculator folders are now organised and I uncovered some ideas (and programs). 

Back to top 


Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565

Posted: 27 Feb 2009 06:07:48 pm Post subject: 


I had an strange and ugly error with my basic execution:
This is related to lists... I was debugging and seeing math programs. Some run Setupeditor and commands like X>dim(list
I have always Omnicalc with Symbolic installed and nothing else unusual installed and then when I used commands like:
L1(1
it run fine but right after doing something like:
Text(X,X,L1(1
2=L1(1 // (and even :L1(1:2=Ans
It always gives ERR:ARGUMENT. After that I reset defaults and made some things and all this was gone. This during math class, seems a nightmare xD
Any idea? I am completely freaked because of this .
More things:
does this optimization is viable? (just taken out a parentheses, and since list is squared there is no problems with negative, but don't know other things)
[quote name='"BASIC Code"']:sum(L5²sum(L6²[/quote]
Instead of:
[quote name='"BASIC Code"']:sum(L5²)sum(L6²[/quote]
Seems to work... And yes, I am really desperate for bytes... I might ask help optimizing the general menu routine.
Now I will finish some programs like the monotonicity, reorganize the menus choices in the my math and optimize some very old things (not sure how, is hard to see your very first codes).
After all this, I definitely got to translate and share both versions (english and portuguese) 

Back to top 


thornahawk μολών λαβέ
Active Member
Joined: 27 Mar 2005 Posts: 569

Posted: 27 Feb 2009 09:07:40 pm Post subject: 


Galandros wrote: does this optimization is viable? (just taken out a parentheses, and since list is squared there is no problems with negative, but don't know other things)
[quote name='"BASIC Code"']:sum(L₅²sum(L₆²
Instead of:
[quote name='"BASIC Code"']:sum(L₅²)sum(L₆²[/quote]
[/quote]
Hmm, yes they are equivalent, this is the distributive law at work... :)
thornahawk 

Back to top 


Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565

Posted: 20 Apr 2009 12:28:14 pm Post subject: 


Galandros wrote: Now I will finish some programs like the monotonicity, reorganize the menus choices in the my math and optimize some very old things (not sure how, is hard to see your very first codes).
Done. Actually 1 or 2 weeks ago.
After discovering more things of derivation, I discovered (alone) that I could use the derivation to keep track if a function increases/decreases instead of my other program.
I made a 2 routines to enter a polynomial into a list:
[quote name='"BASIC Code"']:DelVar L6Input "GRAU POL=",G
:G+1→dim(L6
:For(θ,1,Ans
:Input "X^"+sub("0123456789",G+2θ,1)+"=",A
:A→L6(θ
:End[/quote]
[quote name='"BASIC Code"']:DelVar L6Input "GRAU POL=",G
:G+1→dim(L6
:For(θ,Ans,1,‾1
:Input "X^"+sub("0123456789",θ,1)+"=",A
:A→L6(θ
:End[/quote]
I couldn't optimize further. And it seems friendly input.
the first:
4x^{4}+3x^{3}+2x^{2}+1 would be entered as {4,3,2,0,1}.
the second:
4x^{4}+3x^{3}+2x^{2}+1 would be entered as {1,0,2,3,4}.
I will start reading old math posts at UTI. (teasers and math related) Already found nifty things like Polynomial operations.
The polynomial operations are all in reversed order. Is that way easier to code? Reasons for that.
And I wrote another polynomial operation (derivation). List of polynomial in "reverse" order:
[quote name='"BASIC Code"']:Prompt L6
:DelVar L5
:For(θ,1,dim(L6)1
:θL6(θ+1→L5(θ
:End
:L5[/quote]
I found this rule in my book even before the teacher teach and wrote it in class. How distracted am I?
Meanwhile I got interested in doing something for chemistry in the calculator. Like a equation solver and molecular mass calculator but very optimized.
After my search I found that Ed H already did that 2. Both pretty fast and small. Also the solver is so great that even allows charges. Hopefully I didn't spent my time figuring out how the heck I would do the solver part. (text handling is fine)
I will give link. The equation solver is in TIBD and the other is in UTI topic.
Some TIBASIC:
First: When yoou do a:
Input "=",A
You can enter a list or number... That is a way to crash a BASIC math program...
See what I did in the polynomial routine with the first input of Input...
Last edited by Guest on 11 Jul 2010 05:49:05 pm; edited 1 time in total 

Back to top 


Galandros
Active Member
Joined: 29 Aug 2008 Posts: 565

Posted: 27 Apr 2009 11:21:01 am Post subject: 


I catched a very bad formula implemented...
Now remains to put parts together make some changes and release the beta in portuguese and have courage to translate it...
By know I should give it to my classmates. I made a hidden counter of usage. *evil* I am thinking in an easter egg... 

Back to top 


