You are on page 1of 1

CPSC2150:Instructor Nalin Wijesinghe

Assignment 3: design Due October 06, 08


Naoya Makino: 100106040
Purpose: Implement an Icon program to perform symbolic differention.
Assumptions
This program is implemented by using Icon.
 The symbolic value is x or y
 It does handle only in the given table below.
Definitions
 The derivative is a measurement of how a function changes when the values of its inputs change.
Quoted from: http://en.wikipedia.org/wiki/Derivative
 Lower priority’s operators: +, -
 Higher priority’s operators: *, /, ^
 Trigonometric functions: sin, cos, tan, sec, cosec, cot, sinh, cosh, tanh
Differentiation formulas
Expression Debilitative comment
X^a a * X ^ (a-1) a as constant
X Dx
x+y dx + dy
x*y dx * y + x * dy
X/y (y * dx – x * dy) / y ^ 2
Sin(x) Cos(x)
Cos(x) -Sin(x)
tan(x) Sec(x)^2
Sec(x) Sec(x) * tan(x)
Cosec(x) -cosec(x) * cot(x)
Cot(x) -cosec(x) ^ 2
Sinh(x) Cosh(x)
cosh(x) Sinh(x)
Tanh(x) Sech(x)
C 0 C as constant
Differentiation steps example
1. Sin(2 * x ) + 3 * 2
2. differentiate sin(2 * x)
3. differentiate 3 * 2
4. Apply the operator + for the two result
5. To calculate point 1, we need:
1.1 differentiate sin(2 * x)
1.1.1 differentiate sin(x)
1.1.2 differentiate 2 * x
1.1.3 multiply differentiation of sin(x) and 2*x
Algorithm to handle differentiations
1. find operators
1.1 if there are lower priority’s operators
1.1.1 split expressions at the operator index
1.2 if only higher priority’s operations
1.2.1 call multiply() or divide()
1.3 if no operations
1.3.1 call derive() with the all expression
2 check if operands are trigonometric functions
2.1 if it is trigonometric functions, then call desired functions to derive. ie) sin(), cosa(), tan()
3 if it is non trigonometric functions
3.1 derive operands by the determined function, ie) divide or multiply
4 combined each result
5 then operate lower priority’s operations if any ie) addition or subtraction
Sample inputs and outputs
x^3 = 3 * x^2
cos(2x) = -2 * sin(x)
sin(x^2) + 2x^2 = cos(x^2) * 2 * x + 4 * x

You might also like