Additions:
==Rappresentazione simbolica di funzioni==
%%(java;Fun.scala)
// val f =
// Sub(
// Sum(Prod(X(),X()),
// Prod(Const(2),X()),
// Const(7)
// )
// val g = X()**2 + 2*X() - 7
// println(g(7.5))
// val deriv = g.derivata
sealed abstract class Fun {
def apply(x:Double):Double =
this match {
case Const(i) => i
case X() => x
case Sum(a,b) => a(x)+b(x)
}
case class Const(x:Double) extends Fun
case class X() extends Fun
case class Sum(a:Fun, b:Fun) extends Fun
object TestFun extends App {
val f = Sum(X(),Const(7))
println(f(2.0))
==Alberi binari==
%%(java;Albero.sc)
Deletions:
%%(scala;Albero.sc)
Additions:
%%(scala;Albero.sc)