From 033ec53858cd734ea21853fefb82ff169ca7266c Mon Sep 17 00:00:00 2001
From: Jakob Gabriel <jakob.gabriel@uni-ulm.de>
Date: Mon, 10 Aug 2020 18:24:49 +0200
Subject: [PATCH] fixed #37 + also added methods for quantity.Symbolic and
 unittests

---
 +quantity/Discrete.m                |  2 +-
 +quantity/Symbolic.m                | 16 ++++++++++++++++
 +unittests/+quantity/testDiscrete.m | 16 +++++++++++++++-
 +unittests/+quantity/testSymbolic.m | 15 +++++++++++++++
 4 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/+quantity/Discrete.m b/+quantity/Discrete.m
index 0df4ea4..b1e2850 100644
--- a/+quantity/Discrete.m
+++ b/+quantity/Discrete.m
@@ -1860,7 +1860,7 @@ classdef  (InferiorClasses = {?quantity.Symbolic}) Discrete ...
 		% Complex results are produced if X is not positive.
 			y = quantity.Discrete(log10(obj.on()), obj(1).domain, ...
 				'name', "log10(" + obj(1).name + ")");
-		end % log()
+		end % log10()
 		
 		function xNorm = l2norm(obj, integralGridName, optArg)
 			% calculates the l2 norm, for instance
diff --git a/+quantity/Symbolic.m b/+quantity/Symbolic.m
index 12d00eb..1d5af12 100644
--- a/+quantity/Symbolic.m
+++ b/+quantity/Symbolic.m
@@ -666,6 +666,22 @@ classdef Symbolic < quantity.Function
 				'name', "expm(" + obj(1).name + ")");
 		end % expm()
 		
+		function y = log(obj)
+		%  log    Natural logarithm.
+		%     log(X) is the natural logarithm of the elements of X.
+		%     Complex results are produced if X is not positive.
+			y = quantity.Symbolic(log(obj.sym()), obj(1).domain, ...
+				'name', "log(" + obj(1).name + ")");
+		end % log()
+		
+		function y = log10(obj)
+		% log10  Common (base 10) logarithm.
+		% log10(X) is the base 10 logarithm of the elements of X.   
+		% Complex results are produced if X is not positive.
+			y = quantity.Symbolic(log10(obj.sym()), obj(1).domain, ...
+				'name', "log10(" + obj(1).name + ")");
+		end % log10()
+		
 		function y = ctranspose(obj)
 			% ctranspose() or ' is the complex conjugate tranpose
 			y = quantity.Symbolic(conj(obj.sym().'), obj(1).domain, ...
diff --git a/+unittests/+quantity/testDiscrete.m b/+unittests/+quantity/testDiscrete.m
index 3f06022..4ebeefb 100644
--- a/+unittests/+quantity/testDiscrete.m
+++ b/+unittests/+quantity/testDiscrete.m
@@ -12,8 +12,22 @@ testCase.TestData.sym.t = t;
 testCase.TestData.sym.sy = sy;
 end
 
-function powerTest(testCase)
+function testLog(tc)
+z = quantity.Domain("z", linspace(0, 1, 11));
+quan = Discrete(z) * ones(2, 2) + [1, 1; 0, 0]+0.1*ones(2,2);
+
+tc.verifyEqual(log(quan.on()), on(log(quan)), 'AbsTol', 1e-15);
+tc.verifyEqual(on(quan), on(log(exp(quan))), 'AbsTol', 1e-15);
+end % testLog()
+
+function testLog10(tc)
+z = quantity.Domain("z", linspace(0, 1, 11));
+quan = Discrete(z) * ones(2, 2) + [1, 1; 0, 0]+0.1*ones(2,2);
 
+tc.verifyEqual(log10(quan.on()), on(log10(quan)), 'AbsTol', 1e-15);
+end % testLog10()
+
+function powerTest(testCase)
 t = quantity.Domain("t", linspace(0,1));
 
 p(1,1) = Discrete(t);
diff --git a/+unittests/+quantity/testSymbolic.m b/+unittests/+quantity/testSymbolic.m
index f771ef4..96d5851 100644
--- a/+unittests/+quantity/testSymbolic.m
+++ b/+unittests/+quantity/testSymbolic.m
@@ -4,6 +4,21 @@ function [tests ] = testSymbolic()
 tests = functiontests(localfunctions());
 end
 
+function testLog(tc)
+z = quantity.Domain("z", linspace(0, 1, 11));
+quan = Symbolic(z) * ones(2, 2) + [1, 1; 0, 0]+0.1*ones(2,2);
+
+tc.verifyEqual(log(quan.on()), on(log(quan)), 'AbsTol', 1e-15);
+tc.verifyEqual(on(quan), on(log(exp(quan))), 'AbsTol', 1e-15);
+end % testLog()
+
+function testLog10(tc)
+z = quantity.Domain("z", linspace(0, 1, 11));
+quan = Symbolic(z) * ones(2, 2) + [1, 1; 0, 0]+0.1*ones(2,2);
+
+tc.verifyEqual(log10(quan.on()), on(log10(quan)), 'AbsTol', 1e-15);
+end % testLog10()
+
 function testDet(tc)
 z = quantity.Domain("z", linspace(0, 1, 11));
 zSymbolic = quantity.Symbolic(sym("z"), z);
-- 
GitLab