|
| 1 | +package org.matheclipse.core.reflection.system; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | +import org.matheclipse.core.system.ExprEvaluatorTestCase; |
| 5 | + |
| 6 | +public class MatrixFunctionTest extends ExprEvaluatorTestCase { |
| 7 | + |
| 8 | + @Test |
| 9 | + public void testMatrixFunctionGamma() { |
| 10 | + // example from https://en.wikipedia.org/wiki/Analytic_function_of_a_matrix |
| 11 | + check("mf=MatrixFunction(Gamma, {{1,3},{2,1}})", // |
| 12 | + "{{1/2*(Gamma(1-Sqrt(6))+Gamma(1+Sqrt(6))),1/2*Sqrt(3/2)*(-Gamma(1-Sqrt(6))+Gamma(\n" // |
| 13 | + + "1+Sqrt(6)))},\n" // |
| 14 | + + " {(-Gamma(1-Sqrt(6))+Gamma(1+Sqrt(6)))/Sqrt(6),1/2*(Gamma(1-Sqrt(6))+Gamma(1+Sqrt(\n"// |
| 15 | + + "6)))}}"); |
| 16 | + check("N(mf)", // |
| 17 | + "{{2.81144,0.407999},{0.271999,2.81144}}"); |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + public void testMatrixFunctionSqrt() { |
| 22 | + check("m=MatrixFunction(Sqrt, {{a, 1}, {0, b}})", // |
| 23 | + "{{Sqrt(a),1/(Sqrt(a)+Sqrt(b))},\n" + " {0,Sqrt(b)}}"); |
| 24 | + check("m.m", // |
| 25 | + "{{a,1},\n" // |
| 26 | + + " {0,b}}"); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testMatrixFunctionLog() { |
| 31 | + check("{{2.,2.,1.},{4.,6.,4.},{3.,6.,8.}}=={{2.000000000000001,2.0,0.9999999999999991},\n" |
| 32 | + + " {4.000000000000002,5.999999999999997,3.9999999999999964},\n" |
| 33 | + + " {3.0000000000000093,6.000000000000002,7.999999999999997}}", "True"); |
| 34 | + |
| 35 | + checkNumeric("m ={{2.,2.,1.},{4.,6.,4.},{3.,6.,8.}}", // |
| 36 | + "{{2.0,2.0,1.0},{4.0,6.0,4.0},{3.0,6.0,8.0}}"); |
| 37 | + check("l=MatrixFunction(Log, m)", // |
| 38 | + "{{-0.118314,0.804385,0.0234838},\n" // |
| 39 | + + " {1.60877,1.00354,0.74315},\n" // |
| 40 | + + " {0.0704514,1.11472,1.75383}}"); |
| 41 | + checkNumeric("me=MatrixExp(l)", // |
| 42 | + "{{2.000000000000001,2.0,0.9999999999999991},\n" // |
| 43 | + + " {4.000000000000002,5.999999999999997,3.9999999999999964},\n" // |
| 44 | + + " {3.0000000000000093,6.000000000000002,7.999999999999997}}"); |
| 45 | + check("me==m", // |
| 46 | + "True"); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testMatrixFunction001() { |
| 51 | + check("MatrixFunction(x |-> x^5 + 2 x^2 + 1, {{a, 0}, {1, b}})", // |
| 52 | + "{{1+2*a^2+a^5,0},\n"// |
| 53 | + + " {2*a+a^4+2*b+a^3*b+a^2*b^2+a*b^3+b^4,1+2*b^2+b^5}}"); |
| 54 | + check("MatrixFunction(1 &, {{1, 2}, {3, 4}})", // |
| 55 | + "{{1,0},\n" // |
| 56 | + + " {0,1}}"); |
| 57 | + } |
| 58 | +} |
0 commit comments