News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

The calculator

Started by RuiLoureiro, April 09, 2012, 02:16:47 PM

Previous topic - Next topic

RuiLoureiro

Hi all,
        Here is calcula36, a new version of calcula35
           
        We have the functions point(x1,y1; ... ;x6,y6)
        to put that set of points into a table;
        and the function f(x=a) or f(y=b)
        to execute a linear interpolation.

        When we execute a linear interpolation, the output is

                        X,  Y,  m  and  b             (linear equation: y=mx+b)

        Note that when we try f(x=a) the program sort the table by X
        and use the nearest x point; when we try f(y=a) the program
        sort the table by Y and use the nearest y point.

        Example:
                point(1,2 ; 3,5 ; 5,-1)

                Sorting by X we have: (1,2), (3,5), (5,-1)

        . To calculate f(x=0) it uses the points (1,2) and (3,5)
        . To calculate f(x=2) it uses the points (1,2) and (3,5)
        . To calculate f(x=4) it uses the points (3,5) and (5,-1)
        . To calculate f(x=6) it uses the points (3,5) and (5,-1)
         
                Sorting by Y we have: (5,-1), (1,2), (3,5)

        . To calculate f(y=-2) it uses the points (5,-1) and (1,2)
        . To calculate f(y=0)  it uses the points (5,-1) and (1,2)
        . To calculate f(y=3)  it uses the points (1,2)  and (3,5)
        . To calculate f(y=6)  it uses the points (1,2)  and (3,5)

        Note that, now, the point (5,-1) is near the point (1,2) !

        Try it and say something.
        If you have any idea or suggestion, please answer thsi post

        Thanks
        RuiLoureiro

dedndave


RuiLoureiro

Dave,
        one word to you: thanks !  :wink
       
Hi all,
        Here is calcula37, a new version of calcula36

        . The functions to do a linear interpolation are now
          g(x=a) or g(y=b)or G(x=a) or G(y=b)
          we can use x or X, y or Y;

        . When the output is 1.000000000000, now it is only 1.0
          if the result is 1.000000000000E+0045, now it is only 1.0E+0045

        . sin(pi)=sin(0)= 0  not -0.0000000000000

        error control

        . division by 0:             1/0 is division by 0
        . indeterminate form:   0/0 is an indeterminate form

        functions
       
        . Now we can define a function f(x) [ we must use F(x), F(X), f(X),f(x) ]

        . To define a function we must write f(x)=...
       
          To do it, we write something like this

                        f(x)=x/2-sin(x)/x   [ENTER/COMPUTE]

          To calculate f(0) or f(1.5) we must write

                        f(x=0) or f(x=1.5)

        . With calcula37 we can define

            . a set of 10 variables;              [type: t=12;s=5;f=1e3;          ]
            . a set of 6 points (x,y);           [type: point(1,2; 3,5; 4,8)     ]
            . a function f(x);                      [type: f(x)=x+1                 ]

          * we can solve
         
            . a quadratic equation;               [type: 2x^2+x-1=5               ]
            . a system of 2 equations;          [type: y+x=3; x-y=1;            ]
            . a system of 3 equations;          [type: y+x+z=10; x-y=1; -z+y=5; ]
            . any expression                        [type: (3*15.5+2e3)/(1-5.14)    ]

          * we can do

            . linear interpolation                   [type point(1,2; 3,5) and g(x=2)]

          * we can calculate
           
            . the values of a function f(x)                  [type: f(x=2) or f(x=-1)        ]
            . mean, variance, standard deviation, etc.
            . factorial                                              [type:   6!      ]
            . k-combination of n                               [type: comb(10,6)]

          * we have the system constants

            . pi
            . e
                       
          * we have 6 memories to save expressions

          * we can enter an expression with 200 characters
         
        What next ?
       
            . surprise
       
        Try it and say something.
       
        Is there a bug ? please answer this post
        If you have any idea or suggestion, please answer this post

        Thanks
        RuiLoureiro

RuiLoureiro

Hi all,
        Here is calcula38


        Now, we have 2 more functions:

            . error()

              The system error is 1e-3 if we dont use the function error
              If we want the error equal 1e-5 (ERROR=1e-5) we do

              error(1e-5)   [ENTER/COMPUTE]
             
            . root(x=a, x=b)
              or
            . root(x=a, x=b; n=...)

              The root function try to find the value X where f(X)<= ERROR
              starting at x=a and end at x=b.
             
              The number of sampled points used by the system is n=200.
              If we want n=1000 we use

                        root(x=a, x=b; n=1000)             

        Example:       

                    f(x)=3*x^3-x^2+2*x-1

                    root(x=-1, x=2; n=200)

                    Xc=  0.455; f(Xc)= -0.014435875     (f(Xc) is the closest value)
                    Xmin= -1.0
                    f(Xmin)= -5.0
                    Xmax=  2.0
                    f(Xmax)=  23.0

                    root(x=0, x=1; n=200)
                    X= 0.46
                    f(X)=  0.000408

                    error(1e-5)

                    root(x=0.4454, x=1; n=1000)
                    Xc= 0.4598196; f(Xc)= -0.00013028358895

        Try it and say something.
       
        Is there a bug ? please answer this post
        If you have any idea or suggestion, please answer this post

        Thanks
        RuiLoureiro

dedndave

you write code faster than i do, Rui   :P
i can't keep up with you - lol

jj2007

Quote from: dedndave on April 20, 2012, 03:52:29 PM
i can't keep up with you - lol

Same for me - just incredible ::)
:U

RuiLoureiro

#21
Dave,
Quote
you write code faster than i do, Rui   
i can't keep up with you

         Thanks for reply
         The calculator is faster than me !
Jochen,
Quote
Same for me - just incredible

         Thanks for reply
         It is not fast. It is normal
         

        Here is calcula39


        Now, we have 2 more functions:

        . df(x)=expression to define the derivative of the
          function f(x) (used to solve the equation f(x)=0)

        . root(x=a, x=b; x=X0 ) to solve f(X)=0 (<= ERROR)
          using the Newton method
       
        Examples 1:
                    f(x) =3*x^3-x^2+2*x-1
                    df(x)=9*x^2-2*x+2

                    error(1e-5)

                    root(x=0,x=1;x=0.46)

                    X=0.459863289103337
                    f(X)=0.000000058678523

                    error(1e-9)
                   
                    root(x=0,x=1; x=0.46)
                   
                    X= 0.459863269435932
                    f(X)=  0.000000000000003

                    error(1e-15)
                   
                    root( x=-20, x=20; x=-10 )                   
                    X= 0.459863269435931
                    f(X)= 0

          Now, we can start to find the roots of f(x)
          using, for instance, root(x=-20, x=20; n=200)
          root(x=-20, x=20; n=1000), root(x=-20, x=20; n=10000)
         
          If we find one closest value X0, we define the derivative
          and then we use something like this

                        root(x=-20, x=20; x=X0).

        note: I corrected a bug in the previous calcula38

    EDIT: In root(x=a, x=b; x=X0 ) a, b, X0 can be
            -9pi,...,-1pi, -pi, pi, 2pi, 3pi,...,9pi.
            The same for e 

        Try it and say something.
       
        Is there a bug ? please answer this post
        If you have any idea or suggestion, please answer this post

        Thanks
        RuiLoureiro

dedndave

Rui - you are a math monster !
i bet you would like this site...
http://projecteuler.net/index.php

i have solved about 20 problems so far   :P

RuiLoureiro

Hi all

        Here is calcula40

        Now, we have 2 more functions:

        . df(x=a)=expression

        . root(x=a, x=b)                 n is = 200
          root(x=a, x=b; n=integer)      n from 200 to 1000000
       
          root(x=a, x=b; d=delta )        d = increment  (delta=0.1, 0.01, ...)
          root(x=a, x=b; x= X0 )         X0 =starting point

        . Calcula40 doest accept some typing errors
          when we want to save f(x) or df(x),
          and show the error

        Example:
                  f(x)=2x^2+sen(x)+1            [ENTER/COMPUTE]
                  Error= x^2+sen

                  f(x)=2x^2+sin(x)+1            [ENTER/COMPUTE]
                  Error= 2x^2+sin(x)+1

                  f(x)=2*x^2+sin(x)+1           [ENTER/COMPUTE]
                  The function is defined


        . With calcula40

          * we can define

            . a set of 10 variables;            [type: t=12;s=5;f=1e3;          ]
            . a set of 6 points (x,y);          [type: point(1,2; 3,5; 4,8)     ]
            . a function f(x);           [type: f(x)=x+1                 ]

          * we can define the error to use with root(...)
         
            . error()

              The system error is 1e-3.
              If we want the error equal 1e-5 (ERROR=1e-5) we do

                    error(1e-5)

          * we can solve
         
            . a quadratic equation;             [type: 2x^2+x-1=5               ]
            . a system of 2 equations;          [type: y+x=3; x-y=1;            ]
            . a system of 3 equations;          [type: y+x+z=10; x-y=1; -z+y=5; ]
            . any expression                    [type: (3*15.5+2e3)/(1-5.14)    ]

          * we can solve

            . the equation f(x)=0 using root(...)
           

          * we can do

            . linear interpolation              [type: point(1,2; 3,5) and g(x=2)]

          * we can calculate
           
            . the values of a function f(x)     [type: f(x=2) or f(x=-1)        ]
            . the values of a derivative df(x)  [type: df(x=2) or df(x=-1)      ]
           
            . mean, variance, standard deviation, etc.
            . factorial                                        [type:   6!      ]
            . k-combination of n                               [type: comb(10,6)]

          * we have the system constants

            . pi
            . e
                       
          * we have 6 memories to save expressions

          * we can enter an expression with 200 characters

        What next ?

          . May be to solve a system of 4 linear equations
            showing the determinant (solved by determinants)
         
        Try it and say something.
       
        Is there a bug ? please answer this post
        If you have any idea or suggestion, please answer this post

        Thanks
        RuiLoureiro

RuiLoureiro

#24
Hi all,

        ***Here is calcula41 v1.01***

        1. Detailed questions about pi

            Now, when we use pi we dont need to use *

            In this way, we can type any expression with pi like 

                        n pi  OR  +n pi  OR  -n pi       ( n integer )

                        r pi  OR  +r pi  OR  -r pi       ( r real )

            It is the same as
           
                        n*pi,     +n*pi,     -n*pi       ( we dont need to type * )

                        r*pi,     +r*pi,     -r*pi       ( we dont need to type * )

            If we type 120pi [ENTER/COMPUTE] we get  376.9911184307752

            r may be a scientific notation

                       -2e3pi [ENTER/COMPUTE] we get  -6283.185307179586

            the same as -2e3*pi [ENTER/COMPUTE]


        2. System of 4 linear equations

                . Now we can solve a system of 4 linear equations

                . We must use x,y,z,t or X,Y,Z,T in any order.

            Examples:
           
                   x+y-Z=4; z-T+y=-2; 2x+2t+z=-3; Y-z=5;    [ENTER/COMPUTE]

                   X=-1.0   Y=2.0   Z=-3.0   T=1.0   Determinant=5.0


        Bugs

                If i find a bug, i will post the next calcula42
                                 

        What next ?

                I am waiting for suggestions
               

        Try it and say something.
       
        Is there a bug ? please answer this post
        If you have any idea or suggestion, please answer this post

        Thanks
        RuiLoureiro

    EDIT: qWord, and Dave,
                                      Thanks for reply
                                      I am thinking about your suggestions  :bg

qWord

generalize the parser thus working with vectors/matrices is possible.  Even scalar values could be represented as a 1x1 array:
a = [1,2,3;4,5,6;7,8,9];
b = [10;11;12];
c = a * b;
x = 123  % = [123]
(like matlab  :bg)
FPU in a trice: SmplMath
It's that simple!

dedndave

i was trying to think of ideas   :P

base conversion
prime numbers
fibonacci sequences
taylor and other series (perhaps overdoing it a bit)

if you look at the problems on Project Euler, you may get some ideas
http://projecteuler.net/problems

Farabi

 :U Hey, that was cool, how do you create the parser ??
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

RuiLoureiro

Hi all  :bg

Farabi,
        Hello !
        Thanks for reply
       
Quote
how do you create the parser ??

        It's just the problem !
        But the basic answer is this: thinking and doing
        If you want i can tell you my basic ideas.
        Is simple but i wrote too many procedures to do
        that.

Dave,
Quote
prime numbers
        Thank you for reply
        My problem is how to show a lot of output !
        Give me one suggestion.

qWord,

Quote
generalize the parser thus working with vectors/matrices is possible.
a = [1,2,3;4,5,6;7,8,9];
b = [10;11;12];
c = a * b; 

        Thank you for reply
        For now, i decided to follow your suggestion just as you type.
       
        It is easy to integrate it in the calculator.
        Just now, it is possible to define a vector line,
        vector column or matrix.
        The max number of lines or columns is 20 (very big !)
        We can define a max number of 20 vectors/matrices
        (i think it is enough).

        But ...! There is a problem !
        How to show 400 numbers ? Opening a new window ?

Quote
Even scalar values could be represented as a 1x1 array:

        I decided to reject the case 1x1.
        We can define 10 constants, so it is not needed

RuiLoureiro

#29
Hi all,

        **** Here is calcula42 v1.02 ****


        1. expressions
       
            . The lenght of each expression can be 1200 characters           


        2. round(a,n)

            . n must be one digit 0,1,2,...,9
           
            . new function to round

                a) a real number a
               

                    round(23.51982,2)                   [ENTER/COMPUTE]
                     

                b) each element of a matrix
           
                    array1=[2.456, 1.382, 0.89459];     [ENTER/COMPUTE]
                   
                    round(array1,2)                     [ENTER/COMPUTE]

        3. matrix names

            . Any name starting with a letter with up to 8 characters;

            . We can define up to 20 matrices names;
           

        4. matrix definitions

            . We can define up to 20x20 matrix
           
            . Now we can define a matrix a               
                                                       column 1 column 2  column 3       
                  line 1:    1 , 2 , 3              ->    1         2         3
                  line 2:    4 , 5 , 6              ->    4         5         6
                  line 3:    7 , 8 , 9              ->    7         8         9

            TYPE:
                  a=[1,2,3 ; 4,5,6 ; 7,8,9 ];          [ENTER/COMPUTE]
                 
                  Now, press DELETE KEY and
              type: a  press ENTER/COMPUTE to see the matrix a


            . vector column           
                                                       column 1         
                  line 1:    1 ;                    ->    1         
                  line 2:    4 ;                    ->    4     
                  line 3:    7                      ->    7
                 
                  b=[1 ; 4 ; 7 ];                     [ENTER/COMPUTE]

            . vector line           
                                                       column 1  column 2  column 3       
                  line 1:    1 , 2 , 3              ->    1         2         3

                  b=[1 , 2 , 3 ];                     [ENTER/COMPUTE]


        5. matrix operations

                . Addiction

                    array1=[1, 2; 3, 4];                [ENTER/COMPUTE]
                    array2=[5, 6; 7, 8];                [ENTER/COMPUTE]

                    a=array1+array2;                    [ENTER/COMPUTE]

                . Subtraction

                    array1=[1, 2; 3, 4];                [ENTER/COMPUTE]
                    array2=[5, 6; 7, 8];                [ENTER/COMPUTE]

                    b=array1-array2;                    [ENTER/COMPUTE]

                . Multiplication

                    array1=[1, 2; 3, 4];                [ENTER/COMPUTE]
                    array2=[5, 6; 7, 8];                [ENTER/COMPUTE]

                    c=array1*array2;                    [ENTER/COMPUTE]

                . Scalar multiplication

                    array1=[1, 2; 3, 4];                [ENTER/COMPUTE]
                               
                    d=10 * array1;                      [ENTER/COMPUTE]
                   
                    f=+ array1;                         [ENTER/COMPUTE]
                   
                    g=- array1;                         [ENTER/COMPUTE]
                                 
            note: f=+array1  is <=>  f=array1 and
                  f=-array1  is <=>  f=-1*array1


        6. matrix output

                We show the matrix in the input edit box
                and
                in one messagebox

                Have you any suggestion to show a big 20x20 matrix ?
                Please, let me know
               
        What next ?

                . transpose of a matrix
                . matrix inverse

        Suggestions ?

                How to write to do a transpose of a matrix ?

                b=a^T;      ?????????? (a=matrix m*n)

                How to write to do a matrix inverse ?

                b=a^-1;     ?????????? (a=matrix m*n)

                               
        Try it and say something.
       
        Is there a bug ? please answer this post
        If you have any idea or suggestion, please answer this post

        Thanks to you
       
        Rui Loureiro

EDIT:  Copy this 20*20 matrix 'a' and paste it into the edit box and PRESS ENTER
       Then, try b=a*a;  c=b*b; d=c*c;  .... etc

       
a=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20;
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];