Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Program {
- /* Класс для работы с ФНП */
- class MultivariableFunc(f: (Double, Double) => Double) {
- /* Функция вычисления площади поверхности */
- def S(x1:Double, y1:Double, x2:Double, y2:Double):Double = {
- val dx:Double = 0.001
- val dy:Double = 0.001
- def dT(a:Double, b:Double, c:Double):Double ={
- val p:Double = (a+b+c)/2
- math.sqrt(p*(p-a)*(p-b)*(p-c))
- }
- def dS(x:Double, y:Double):Double ={
- val A:Double = math.sqrt(math.pow(dx, 2) + math.pow(f(x+dx, y)-f(x, y), 2))
- val B:Double = math.sqrt(math.pow(dy, 2) + math.pow(f(x+dx, y+dy)-f(x+dx, y), 2))
- val C:Double = math.sqrt(math.pow(dx, 2) + math.pow(f(x, y+dy)-f(x+dx, y+dy), 2))
- val D:Double = math.sqrt(math.pow(dy, 2) + math.pow(f(x, y)-f(x, y+dy), 2))
- val E:Double = math.sqrt(math.pow(dx, 2) + math.pow(dy, 2) + math.pow(f(x, y)-f(x+dx, y+dy), 2))
- dT(A, B, E) + dT(C, D, E)
- }
- var s:Double = 0
- for(x:Double <- x1.to(x2, dx)){
- for(y:Double <- y1.to(y2, dy))
- s+=dS(x, y)
- }
- return s
- }
- }
- def main(args:Array[String]){
- /* Создаём экземпляр класса для функции f(x,y)=xy */
- val f = new MultivariableFunc((x:Double, y:Double) => x*y)
- /* Считаем площадь поверхности от A:(-1;-1) до B(1;1) */
- val S:Double = f.S(-1, -1, 1, 1)
- Console.println(S)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement