@@ -342,28 +342,42 @@ using Base: oneto
342
342
343
343
@test F (1.5 ,1.5im ) ≈ hankelh1 (0 ,10 abs (1.5im - 1.5 ))
344
344
345
+ P = ProductFun ((x,y)-> x^ 2 * y^ 3 , Chebyshev () ⊗ Chebyshev ())
346
+ @test (Derivative () * P)(0.1 , 0.2 ) ≈ ProductFun ((x,y)-> 2 x* y^ 3 )(0.1 , 0.2 )
347
+ @test (P * Derivative ())(0.1 , 0.2 ) ≈ ProductFun ((x,y)-> x^ 2 * 3 y^ 2 )(0.1 , 0.2 )
348
+
345
349
P = ProductFun ((x,y)-> x* y, Chebyshev () ⊗ Chebyshev ())
346
- x = Fun (); y = x;
347
- @test Evaluation (1 ) * P == x
348
- @test Evaluation (- 1 ) * P == - x
350
+ xf = Fun (); yf = xf;
351
+ xi, yi = 0.1 , 0.2
352
+ x, y = xf (xi), yf (yi)
353
+ @test Evaluation (1 ) * P == xf
354
+ @test Evaluation (- 1 ) * P == - xf
349
355
D1 = Derivative (Chebyshev () ⊗ Chebyshev (), [1 ,0 ])
350
356
D2 = Derivative (Chebyshev () ⊗ Chebyshev (), [0 ,1 ])
351
- @test (D2 * P)(0.1 , 0.2 ) ≈ x (0.1 )
352
- @test (D1 * P)(0.1 , 0.2 ) ≈ y (0.2 )
353
- @test ((P * D1) * P)(0.1 , 0.2 ) ≈ x (0.1 ) * (y (0.2 ))^ 2
354
- @test ((P * D2) * P)(0.1 , 0.2 ) ≈ (x (0.1 ))^ 2 * y (0.2 )
355
- @test ((I ⊗ Derivative ()) * P)(0.1 , 0.2 ) ≈ x (0.1 )
356
- @test ((Derivative () ⊗ I) * P)(0.1 , 0.2 ) ≈ y (0.2 )
357
+ @test (D2 * P)(xi, yi) ≈ x
358
+ @test (D1 * P)(xi, yi) ≈ y
359
+ @test ((P * D1) * P)(xi, yi) ≈ x * y^ 2
360
+ @test ((P * D2) * P)(xi, yi) ≈ x^ 2 * y
361
+ @test ((I ⊗ Derivative ()) * P)(xi, yi) ≈ x
362
+ @test ((Derivative () ⊗ I) * P)(xi, yi) ≈ y
363
+
364
+ # distribute over plus operator
365
+ @test ((D1 + Multiplication (xf)⊗ I) * P)(xi, yi) ≈ y + x^ 2 * y
366
+ @test ((P * (D1 + Multiplication (xf)⊗ I)) * P)(xi, yi) ≈ x * y^ 2 + x^ 3 * y^ 2
367
+
368
+ A = (Multiplication (xf)⊗ I) * Derivative (Chebyshev ()^ 2 , [0 ,1 ])
369
+ @test (A * P)(xi, yi) ≈ x^ 2
357
370
358
371
# MultivariateFun methods
359
372
f = invoke (* , Tuple{KroneckerOperator, ApproxFunBase. MultivariateFun},
360
373
Derivative () ⊗ I, P)
361
- @test f (0.1 , 0.2 ) ≈ y ( 0.2 )
374
+ @test f (xi, yi ) ≈ y
362
375
O = invoke (* , Tuple{ApproxFunBase. MultivariateFun, KroneckerOperator},
363
376
P, Derivative () ⊗ I)
364
- @test (O * Fun (P))(0.1 , 0.2 ) ≈ x ( 0.1 ) * ( y ( 0.2 )) ^ 2
377
+ @test (O * Fun (P))(xi, yi ) ≈ x * y ^ 2
365
378
366
379
@testset " chopping" begin
380
+ local P
367
381
M = [0 0 0 ; 0 1 0 ; 0 0 1 ]
368
382
P = ProductFun (M, Chebyshev () ⊗ Chebyshev (), chopping = true )
369
383
@test coefficients (P) == M
@@ -377,6 +391,23 @@ using Base: oneto
377
391
P = ProductFun (M, Chebyshev () ⊗ Chebyshev (), chopping = true )
378
392
@test all (iszero, coefficients (P))
379
393
end
394
+
395
+ @testset " KroneckerOperator" begin
396
+ local P
397
+ P = ProductFun ((x,y)-> x^ 2 * y^ 3 , Chebyshev () ⊗ Chebyshev ())
398
+ A = Multiplication (xf)⊗ I
399
+ a = (KroneckerOperator (A) * P)(xi, yi)
400
+ b = (A * P)(xi, yi)
401
+ @test a ≈ b
402
+ a = ((P * KroneckerOperator (A)) * P)(xi, yi)
403
+ b = ((P * A) * P)(xi, yi)
404
+ @test a ≈ b
405
+ # distribute a KroneckerOperator over a times operator
406
+ A = (Multiplication (xf)⊗ I) * Derivative (Chebyshev ()^ 2 , [0 ,1 ])
407
+ a = ((P * A) * P)(xi, yi)
408
+ b = ((P * KroneckerOperator (A)) * P)(xi, yi)
409
+ @test a ≈ b
410
+ end
380
411
end
381
412
382
413
@testset " Functional*Fun" begin
@@ -395,4 +426,13 @@ using Base: oneto
395
426
f= Fun ((x,y)-> [exp (x* cos (y)) cos (x* sin (y)); 2 1 ],ChebyshevInterval ()^ 2 )
396
427
@test f (0.1 ,0.2 ) ≈ [exp (0.1 * cos (0.2 )) cos (0.1 * sin (0.2 ));2 1 ]
397
428
end
429
+
430
+ @testset " grad" begin
431
+ f = Fun ((x,y)-> x^ 2 * y^ 3 , Chebyshev ()^ 2 )
432
+ g = grad (f)
433
+ @test g == grad (space (f))* f == grad (domain (f)) * f
434
+ x = 0.1 ; y = 0.2
435
+ @test g[1 ](x, y) ≈ 2 x* y^ 3
436
+ @test g[2 ](x, y) ≈ x^ 2 * 3 y^ 2
437
+ end
398
438
end
0 commit comments