Skip to content

Commit

Permalink
Adding inverse trig functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
btmy87 committed Aug 27, 2024
1 parent 5d6afb6 commit 3ba27d2
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
10 changes: 10 additions & 0 deletions @UncVal/acos.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function obj = acos(x)
%ACOS acos function for UncVal objects
obj = x;
obj.val = acos(x.val);
m = -1.0./sqrt(1-x.val.^2);
for k = obj.srcs.keys'
obj.srcs(k).sens = m.*obj.srcs(k).sens;
end
end

4 changes: 4 additions & 0 deletions @UncVal/acosd.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function obj = acosd(x)
% acosd arccosine in degrees
obj = rad2deg(acos(x));
end
10 changes: 10 additions & 0 deletions @UncVal/asin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function obj = asin(x)
%ASIN asin function for UncVal objects
obj = x;
obj.val = asin(x.val);
m = 1.0./sqrt(1-x.val.^2);
for k = obj.srcs.keys'
obj.srcs(k).sens = m.*obj.srcs(k).sens;
end
end

4 changes: 4 additions & 0 deletions @UncVal/asind.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function obj = asind(x)
% asind arcsine in degrees
obj = rad2deg(asin(x));
end
10 changes: 10 additions & 0 deletions @UncVal/atan.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function obj = atan(x)
%ATAN arctangent function for UncVal objects
obj = x;
obj.val = atan(x.val);
m = 1.0./(1+x.val.^2);
for k = obj.srcs.keys'
obj.srcs(k).sens = m.*obj.srcs(k).sens;
end
end

4 changes: 4 additions & 0 deletions @UncVal/atand.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function obj = atand(x)
% atand arctangent in degrees
obj = rad2deg(atan(x));
end
42 changes: 42 additions & 0 deletions TEST_UncVal_simple.m
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,48 @@
assertClose(y.val, 0.0);
assertClose(var(y), 0.0);

%% Test asin
x = UncVal(0.3, 0.01, "x");
y = asin(x);
z = sin(y);
assertClose(z.val, x.val);
assertClose(var(z), var(x));

%% Test asind
x = UncVal(18, 1, "x");
y = asind(x);
z = sind(y);
assertClose(z.val, x.val);
assertClose(var(z), var(x));

%% Test acos
x = UncVal(0.3, 0.01, "x");
y = acos(x);
z = cos(y);
assertClose(z.val, x.val);
assertClose(var(z), var(x));

%% Test acosd
x = UncVal(18, 1, "x");
y = acosd(x);
z = cosd(y);
assertClose(z.val, x.val);
assertClose(var(z), var(x));

%% Test atan
x = UncVal(0.3, 0.01, "x");
y = atan(x);
z = tan(y);
assertClose(z.val, x.val);
assertClose(var(z), var(x));

%% Test atand
x = UncVal(18, 1, "x");
y = atand(x);
z = tand(y);
assertClose(z.val, x.val);
assertClose(var(z), var(x));

%% Test trig in degrees
x = UncVal(25.0, 0.1, "x");
y1 = sind(x);
Expand Down

0 comments on commit 3ba27d2

Please sign in to comment.