Monday, July 24, 2006

Solving Equations in Dicom

To some extent Dicom conversion calculator can be used to solve equations. If an equation can be written in a manner so that it converges on each iteration you can easily solve that equation in Dicom.

Let us consider the following equation:

x^3-17*x+12=0

The equation is a polynomial of third degree. We may re-write it as

x=(17*x-12)^(1/3)

The process of solving this equation is - at first we assume a value of x and then calculate the right hand side (RHS) with the assumed value of x. We then better our assumption with the new value of x as the calculated value and continue this process untill assumed value and calculated value converge within the range we can tolerate.


If we solve the equation manually with an assumed value of x=1, the result will be as follows:

Iteration Assumed (x) Calculated (RHS)
1 x=1.00 1.71
2 x=1.71 2.57
3 x=2.57 3.16
4 x=3.16 3.47
.. .. ..
After a few iterations we will have x=3.71 and RHS=3.71 which may be considered as the solution to the value of x with acceptable accurcy.

Using Dicom this process can be carried out automatically. To do this we need to use expression opeartor (:=) and Loop() function in Dicom.

Expression Operator

The expression operator is an unique feature of Dicom conversion calculator which tells Dicom to remember the expression and recalculate whenever a variable of the expression is changed. This operator is different from assignment (=) opeartor.

In short, the difference between expression operator (:=) and assignment operator (=) is that the expression operator assigns expression to a memory variable, while the assignment operator assigns value to a memory variable.

We can define the right hand side of the equation as the expression y as below:
y := (17*x-12)^(1/3)

to see how expression (:=) operator works in Dicom, enter the following in Dicom calculator and press enter.

x=1; y

You will see the result being1.7099759466767. N
ow change the value of x=1 to x=2 and press enter. Voila, the value of y has also been changed to 2.80203933065539.

Loop() Function

Now we need to evaluate y with calculated value on each iteration. Dicom Loop() function syntax is as below:

Loop( intNum, 'exprn')

Where, intNum is an integer number denoting the no of iterations and exprn is the expression to iterate and should be written within single quotes.

We want to assume the first value of x=1; then we calculate the value of y and assign the calculated value to x. So expression we want to iterate is 'x=y'. Let's iterate it 20 times. Below is the resulting dicom instructions:

y := (17*x-12)^(1/3)
; x=1; Loop(20, 'x=y')

Cut and paste the above instructions in Dicom calculator. You will get the value of x after 20 iteration and it is 3.71021341594725.

Let's recalculate it for 100 iterations:

y := (17*x-12)^(1/3)
; x=1; Loop(100, 'x=y')

And we get x=
3.71021358587913

To clear out Dicom memory i.e. any previous assignment, expression, etc. you may use RECLAIM command before issuing new instructions to Dicom that stores memory varables.

Example:
RECLAIM; y := (17*x-12)^(1/3) ; x=1; Loop(100, 'x=y')

Grab a copy of Dicom, it is absolutely free. You can download it here.