Pretty Good Calculator

Posted By: mk_1

Pretty Good Calculator - 05/16/11 11:24

Since Matlab is expensive, GNU Octave takes too long to start and the Windows(tm) Calculator ... well ... sucks ... I decided to write my own one, which now needs some testing.

http://mk-scape.de/down/pgc.zip

It still doesn't support anything I want but this is going to change in the future. Right now you can do all basic calculations and also use vectors/matrices by placing theirs comonents in parenthesis:
Code:
(1,2,3) vector or (1,2;3,4) 2x2 matrix


You can assign values to variables by using = or forward arrow
Code:
a = 3
3 -> a


There are some basic functions implemented. Descriptions are available by typing
Code:
help(function_name)


Trigonometric functions are in radians, I'm going to add a DEG/RAD switch later on.

You can copy the ans(wer) value to the clipboar by pressing Ctrl+P.

Vector multiplication: There are two different operators which can be used.
Code:
(1,2,3) * (3,4,5)' does a dot product. Please note that the second vector is transposed using an apostrophe.

(1,2,3) .* (3,4,5) does a component wise multiplication

.

You can create a vector of increasing values by using the range operator:
Code:
x = 0:255   Create vector of length 256 filled with all numbers from 0 to 255

x = 0:0.5:10 Create a vector from 0 to 10 with steps of 0.5, i.e. (0, 0.5, 1, 1.5, ...)



You can also plot functions but the plot window isn't really done yet and only displays graphs in the range -4 to 4 in x and y. Example:
Code:
x = -4:0.05:4
y = plot(sinh(x);cosh(x);tanh(x))



Operators:
Code:
+ add
- sub
* mul
/ div
! factorial
= assign to left
-> assign to right
^ power
, column delimiter
; row delimiter
x:y range
x:y:z range with steps unequal 1



Feel free to report any bugs here.
Posted By: Joozey

Re: Pretty Good Calculator - 05/16/11 11:32

How can i plot then?
Looks good!
Posted By: Joey

Re: Pretty Good Calculator - 05/16/11 11:34

draws 50% cpu all time, hangs on exit. i'd also interchange .* and *. also, suggestion popup menu does not show up properly, it re-disappears immediately. i think i'll stick with mathematica wink.
Posted By: mk_1

Re: Pretty Good Calculator - 05/16/11 11:37

Sorry, missed "plot", I edited my first post.
I just noticed it takes 50% cpu time, will change that. Why change .* and *. ? Most people are used to it from matlab. Popup menu disappears instantly because it shouldn't be displayed in the first place. I know all of these problems.

It's more about if all the functions and operators work properly.
Posted By: Inestical

Re: Pretty Good Calculator - 05/16/11 11:39

One thing seems missing from the operators:

% modulo
Posted By: mk_1

Re: Pretty Good Calculator - 05/16/11 11:51

I'm going to add modulo, totally forgot that.

What this is really about is to type in all the stuff and then export this to LaTeX / MathML. I also used it to create look up tables for a µC. Vectors/Matrices are automatically transformed into valid C code.
Posted By: Xarthor

Re: Pretty Good Calculator - 05/16/11 12:36

Sounds interesting. Did you check out freemat? http://freemat.sourceforge.net/
Posted By: mk_1

Re: Pretty Good Calculator - 05/16/11 12:53

The biggest difference to all available calculators out there is the fact that you can choose any precision you want and are not restricted to 128bit values.

EDIT: fixed cpu problem. Included in next update along with modulo and any other bug you can find.
Posted By: Joey

Re: Pretty Good Calculator - 05/16/11 15:32

.* sounds like "dot product", while * is the common product on the field. also, matlab seemed very inconsistent to me from what i've heard (especially when it comes to naming and function arguments).

what about python? you could use its power and write a latex/mathml exporter for the command line history. just a thought. i don't want to discourage you.

edit: mathematica (and python, by the way) has arbitrary precision.
edit2: and mathematica has latex and mathml output. don't you get a license at your university?
Posted By: mk_1

Re: Pretty Good Calculator - 05/16/11 15:49

You don't. I wrote this for me so I don't care. wink
You are right that .* sounds like a dot product but since multiplication is not the only operator that can be used component wise it makes sense. You can e.g. use x.^2 on a matrix or divide each component by using ./

I like Python but it doesn't support matrices if you don't add NumPy and there's still a restriction on precision which applies to all calcs I know so far. It makes performing big matrix operations a lot slower but I can live with that as long as the results are as precise as I need them.
Posted By: Joey

Re: Pretty Good Calculator - 05/16/11 16:49

do you use your own number class then? will you add control structures to the calculator?
Posted By: mk_1

Re: Pretty Good Calculator - 05/16/11 22:09

I'm using mapm for the numbers and my own structure for complex numbers and matrices. I'm not sure about control structures. In the end this calculator shall be a simple tool. I'll add functions which are just several actions executed but that's it, no conditions, no loops. Conditions can be accomplished by some functions I'll add (see matlab's "any") and comparators which are still to be implemented. Loops can almost always be done with a range vector.
Posted By: mk_1

Re: Pretty Good Calculator - 05/21/11 12:36

There's a new version: Download

Changes:

  • fixed cpu processing time
  • fixed popup of autocomplete window
  • added modulo "%"
  • added comparators (same as in C)
  • added "any" function


Please report any unusual behaviour. I'm not sure if my parser is working correctly so try some terms that don't make sense (like several "+" in a row)
Posted By: Inestical

Re: Pretty Good Calculator - 05/21/11 13:33

okay, I made it crash

5+5:20

EDIT: I can't reproduce it..
Posted By: mk_1

Re: Pretty Good Calculator - 05/21/11 14:42

Negative ranges crash it (like 5:2 where it should be 5:-1:2), thx
Posted By: Joey

Re: Pretty Good Calculator - 05/21/11 16:31

.2 isn't recognized. also, you can do weird stuff like (2:4)+(3:5)*2/(2.4:2.58). crashes when doing something like 1:(2^20) and then quitting the program.
Posted By: mk_1

Re: Pretty Good Calculator - 05/21/11 16:54

.2 yes, something I should add
the weird stuff is correct. It's two 2-component vectors added and one of them is multiplied by a scalar.

1:(2^20) doesn't crash. it only takes time. I'm going to move the calculation to another thread for the next update.
Posted By: Joey

Re: Pretty Good Calculator - 05/21/11 17:16

no, it doesn't crash immediately but when i quit the program afterwards.

edit: just noticed that it always crashes on exit.
© 2024 lite-C Forums