//
//  Function.swift
//  MN
//
//  Created by Rafael Escaleira on 11/09/19.
//  Copyright © 2019 Rafael Escaleira. All rights reserved.
//

import Foundation

public class Function: NSObject {
    
    private var expoentes: [Double] = []
    private var coeficientes: [Double] = []
    
    public init(expoentes: [Double], coeficientes: [Double]) {
        
        self.expoentes = expoentes
        self.coeficientes = coeficientes
    }
    
    public func getValueFunction(x: Double) -> Double {
        
        var value: Double = 0
        
        for i in 0 ... (self.expoentes.count - 1) {
            
            value = value + (self.coeficientes[i] * pow(x, self.expoentes[i]))
        }
        
        return value
    }
    
    public func getValueDerivativeFunction(x: Double) -> Double {
        
        var value: Double = 0
        
        for i in 0 ... (self.expoentes.count - 1) {
            
            value = value + (self.expoentes[i] * (self.coeficientes[i] * pow(x, self.expoentes[i] - 1)))
        }
        
        return value
    }
}
