Advertisement
Guest User

Untitled

a guest
Jan 28th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun poly [] x = 0.0
  2.   | poly (hd::tl) x = hd + x*(poly tl x);
  3.                      
  4. poly = [1,2,3]
  5.  
  6. ##If polynomials exists solely as a list of coefficients,
  7. ##then to differentiate, we must first drop the first element of the list,
  8. ##then multiply each element of the list by it's index.
  9.  
  10. For example diff [1,2,3] -> [2, 6]
  11.             diff (1 + 2x + 3x^2) -> (2 + 6x)
  12.            
  13.  
  14.  
  15.  
  16. fun diff L = let fun mult_elements n [] = []
  17.                    | mult_elements n (hd::tl) = (n*hd)::mult_elements (n+1) tl
  18.              in tl (mult_elements 0 L) end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement