Author Topic: The calculator  (Read 129417 times)

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: The calculator
« Reply #120 on: June 13, 2016, 08:32:51 AM »
Hi HSE,
Could you post the first partial derivative of sin(a-2.0*9/2*x/b) with respect to the variable b and a ? It is just to see the solution.

HSE

  • Member
  • *****
  • Posts: 2502
  • AMD 7-32 / i3 10-64
Re: The calculator
« Reply #121 on: June 14, 2016, 01:01:27 AM »
Hi Rui!

          df/da = cos(a-9*x/b)
          df/db = 9*x*b^(-2)*cos(a-9*x/b)


 It`s my solution, perhaps not the solution. :biggrin: 
Equations in Assembly: SmplMath

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: The calculator
« Reply #122 on: June 14, 2016, 08:54:56 AM »
Hi Rui!

          df/da = cos(a-9*x/b)
          df/db = 9*x*b^(-2)*cos(a-9*x/b)

 It`s my solution, perhaps not the solution. :biggrin:
:biggrin:
Hi HSE,
     Yes it is the solution. Is it the solution shown by your
calculator ? It should be:
          DER.a = cos(a-9*x/b)
          DER.b = 9*x*b^(-2)*cos(a-9*x/b)

In any way why (-2) ? Why not 9*x*b^-2 ? After '^' the sign must belong
to the next number (or literal constant) or it is an error. No ?

HSE

  • Member
  • *****
  • Posts: 2502
  • AMD 7-32 / i3 10-64
Re: The calculator
« Reply #123 on: June 14, 2016, 10:44:12 PM »
Hi Rui!

DER.a, etc is the way to charge derivatives in the package that solve Levenberg-Marquardt. I'm my calculator(OK, the table of rules is the calculator 8)).

After to read about Shunting-Yard the Saturday, on Sunday I tried to write a solver  :biggrin:. I give up at this point:

Quote
            psal -> [2+4*2/(1-5)^2^3]' = 0


I put the parenthesis because is more easy to read. 1/b^2 also is nice. Not very important.

Yesterday I downloaded a couple of solvers in Java, don't work yet because they need extra libraries, perhaps take some time to see what they do.
Equations in Assembly: SmplMath

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: The calculator
« Reply #124 on: June 15, 2016, 08:57:42 AM »
RuiLoureiro,

just for personal interest: how do you store the parsed expressions? As tree?

regards
MREAL macros - when you need floating point arithmetic while assembling!

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: The calculator
« Reply #125 on: June 17, 2016, 09:00:21 AM »
RuiLoureiro,

just for personal interest: how do you store the parsed expressions? As tree?

regards

Hi qWord,
         i store parsed expressions in tables one after another. The length of
         each line is a constante (2^N). It is saved from top to bottom
         and removed from bottom to top (it is like push, push, push and pop, pop, pop).
         In some cases i store the function itself to be solved later. So
         i have one table for derivatives and another for functions.
         
         I have one table of basic functions (Fnc1, Fnc2,...,FncN) and tables
         of basic derivatives (Drv1,Drv2,...,DrvN): for argument X, for -X, 1/X, ...
         The first step is to solve functions. The last is to solve something
         like 1+x-x^2+x^-5+e^x, etc. (expressions without brackets).

         Could you post an expression to be solved ?
         Thanks
regards  :t

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: The calculator
« Reply #126 on: June 19, 2016, 02:57:16 AM »
Hi,
not so easy to find some expression, because nested functions (e.g. sin(cos(x))) are currently not implemented.
One thing I found is that
(-2^x)'
fails with
(-2^x)' = -2  ↯

Alos to note that editing expression is very unintuitive, because the DEL key clears the control rather than removing just one character (definitively breaks usability).

regards
MREAL macros - when you need floating point arithmetic while assembling!

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: The calculator
« Reply #127 on: June 19, 2016, 09:06:02 AM »
Hi,
not so easy to find some expression, because nested functions (e.g. sin(cos(x))) are currently not implemented.
One thing I found is that
(-2^x)'
fails with
(-2^x)' = -2  ↯

Alos to note that editing expression is very unintuitive, because the DEL key clears the control rather than removing just one character (definitively breaks usability).

regards
Hi qWord,
             many thanks for your reply
             Tomorrow i will see what about that expression.
             I replaced my copy procedure but the last has a bug !
Thank you so much  :t

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: The calculator
« Reply #128 on: June 20, 2016, 03:35:41 AM »
Hi qWord,
           First of all, many thanks for your reply.
           Five things:
           
           1.   I got calcula67 from the first post in this forum.
                It is «The Calculator v2014.05 by RuiLoureiro»
                Using it i get this:               

                                   (a)      (2^x)' = ln(2)*2^x   
                AND THIS 
                                   (b)     (-2^x)' = ln(2)*2^x 

                       NOTE: the correct solution for (b) would be -ln(2)*2^x
                                  because (-2^x)'= -1*(2^x)'
                                  and [2^x]'=[e^(x*ln(2))]' = [x*ln(2)]' * 2^x = ln(2) * 2^x

                It means that the case (b) is wrong but it gives a solution and does't fail.
                I don't know why you don't get a solution!

            2. I know that the copy procedure used by calcula67 has a bug. I'm working now
               in calcula68, «The Calculator v2016.01» and some bugs was corrected.

            3. About nested functions, like sin( cos(x) ) or  sin( cos(x)+x^2-1 ),
               it is not implemented in the calcula67. I will try to implement it
               in the next calcula68 if i have time to do it. At least some cases.

            4. About the DEL key, i will correct it, thank you for the suggestion.
               
            5. About the new version
           
               In the previous calcula67, we get things like this:
               
               (-ln(x))' = -[1/x]   OR     (-arcsin(x))'=-[1/sqr(1-x^2)]

               I don't like these solutions. In the new version, it will be:
               
               (-ln(x))' = -1/x    and     (-arcsin(x))'=-1/sqr(1-x^2) and ...

Thank you so much.  :t

EDIT:
qWord,
Your suggestions are always good.
I don't forget that i developed some things with your suggestions - see the old forum.
« Last Edit: June 20, 2016, 08:06:18 AM by RuiLoureiro »

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: The calculator
« Reply #129 on: June 20, 2016, 08:42:08 AM »
qWord,
       I want to write a general procedure to identify a general power function
(or exponential).

           The PowerFuncX must be:  _BaseArgumentX ^ _ExpoArgumentY
           where
           _BaseArgumentX and _ExpoArgumentY are strings;
           K, N are integers; X,Y are real10
           and   
           _BaseArgumentX  - must be INTEGER K  constant
                                                        REAL        X       "
                                                        10      - particular case K=10
                                                         x
                                                         e
                                                        FncX(x)
                                                        expressionX

           _ExpoArgumentY  - must be INTEGER    N    constant
                                                        RATIONAL (K/N)     "
                                                        REAL           Y           "
                                                         x
                                                         e
                                                        FncY(x)
                                                        expressionY

      Note: In general, the left side is X, the right side is Y, so we have
               X operation Y, where operation is a code for: +, -, *, /, ^.

      Example 1: we may type [-x ^ (x-1)]'           => [ - x ^ expressionY ]'
      Example 2: we may type [10.54 ^ sin(x-1)]' => [ REAL X ^ FncY ]'

Do you want to give me any suggestion ?
Thanks  :t

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: The calculator
« Reply #130 on: June 20, 2016, 10:54:50 AM »
you might see if this code works for you...

http://masm32.com/board/index.php?topic=222.0

the IntExp_1 download

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: The calculator
« Reply #131 on: June 21, 2016, 09:40:27 AM »
I want to write a general procedure to identify a general power function
[...]
Do you want to give me any suggestion ?
I would, but I'm not sure about your question. And without knowing the exact data structure it hard to give any help.

You have parsed the expression in some table(s), respecting the operator precedence and associativity for the purpose of evaluation (not necessarily for derivation). For common evaluation (means no variables) you traverse the table from bottom to top, substituting the entries in row n-1 with results from row n.
The problem is that you must apply the rules of derivation from top to bottom in table. Furthermore the expression grows due to the rules (e.g. (f ⋅g)' = f'⋅g + f⋅g'), so you may need to  create a new table when applying derivation rules (or the table "grows into the third dimension"). If f' is some basic function like sin, cos, exp, ... you use tables to look up f' for particular arguments (does not sound practical because the set of possible arguments is infinite).
Did I get it right so far? You might show a graphic of your data structure.

regards

MREAL macros - when you need floating point arithmetic while assembling!

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: The calculator
« Reply #132 on: June 22, 2016, 08:43:05 AM »
you might see if this code works for you...

http://masm32.com/board/index.php?topic=222.0

the IntExp_1 download
Hi Dave
       How are you , my old friend ?
About the code, i am writing one.
I have a lot of work done.
See this:
[sin(x^2-x)^(2/3) * cos(x-x^2)^(1/2) ]'=
(2/3)*(2*x-1)*cos(x^2-x)*sin(x^2-x)^(-1/3)*cos(x-x^2)^(1/2)-(1/2)*(1-2*x)*sin(x-x^2)*cos(x-x^2)^(-1/2)*sin(x^2-x)^(2/3)
I am using The calculator - calcula67.
Thank you so much, Dave  :t

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: The calculator
« Reply #133 on: June 22, 2016, 09:17:46 AM »
I want to write a general procedure to identify a general power function
[...]
Do you want to give me any suggestion ?
I would, but I'm not sure about your question. And without knowing the exact data structure it hard to give any help.

You have parsed the expression in some table(s), respecting the operator precedence and associativity for the purpose of evaluation (not necessarily for derivation). For common evaluation (means no variables) you traverse the table from bottom to top, substituting the entries in row n-1 with results from row n.
The problem is that you must apply the rules of derivation from top to bottom in table. Furthermore the expression grows due to the rules (e.g. (f ⋅g)' = f'⋅g + f⋅g'), so you may need to  create a new table when applying derivation rules (or the table "grows into the third dimension"). If f' is some basic function like sin, cos, exp, ... you use tables to look up f' for particular arguments (does not sound practical because the set of possible arguments is infinite).
Did I get it right so far? You might show a graphic of your data structure.

regards

Hi qWord
        Thanks for your reply
No, i dont do what you are saying.

To solve this: [1-x^2+e^-x]' i dont use any table. The general procedure do this.
To solve this: [x-x^2 - sin(x^2-x)]' i solve [sin(x^2-x)]' and the result is saved in one table for 20
functions (i defined 20 but it can be 50 or 100 or ...). The last step is to solve [x-x^2]'
The result is added with the result that i get from the table.

To solve [sin(x^2-x)]' i get cos(Y) from a derivative table and i replace Y by x^2-x to get cos(x^2-x).
I call the general procedure that solves [x^2-x]' and then i multiply (2*x-1) by cos(x^2-x). This result
is saved in the derivative table.
The derivative table for simple functions is something like this:
Function Number      Function Name   Derivative
1                                   ln(x)                      1/x
...
5                                   cos(x)                   -sin(x)
...
N                                   arctan(x)                 ...

When we find 'cos(???)' we get the function number 5. If the function number is 5 the derivative is
-sin(???)

Thanks  :t
regards
« Last Edit: June 23, 2016, 09:31:25 AM by RuiLoureiro »

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: The calculator
« Reply #134 on: June 23, 2016, 06:32:31 AM »
OK, so you do parsing on the fly and not as separate step (that was my thought).

regards
MREAL macros - when you need floating point arithmetic while assembling!