Skip to content

Commit 3343dab

Browse files
Add validators for numeric values including symbolic
1 parent 3301f30 commit 3343dab

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function result = isNumerical(x)
2+
3+
result = isnumeric(x) || isa(x, 'sym');
4+
5+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function mustBeNumerical(x)
2+
3+
if ~otp.utils.validation.isNumerical(x)
4+
throwAsCaller(MException('OTP:notNumeric', 'Value must be numeric.'));
5+
end
6+
7+
end

src/+otp/Problem.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ function validateNewState(obj, newTimeSpan, newY0, newParameters)
121121
% Ensures the TimeSpan, Y0, and Parameters are valid
122122
if length(newTimeSpan) ~= 2
123123
error('TimeSpan must be a vector of two times');
124-
elseif ~(isnumeric(newTimeSpan) || isa(newTimeSpan, 'sym'))
124+
elseif ~otp.utils.validation.isNumerical(newTimeSpan)
125125
error('TimeSpan must be numeric');
126126
elseif ~iscolumn(newY0)
127127
error('Y0 must be a column vector');
128-
elseif ~(isnumeric(newY0) || isa(newY0, 'sym'))
128+
elseif ~otp.utils.validation.isNumerical(newY0)
129129
error('Y0 must be numeric');
130130
elseif ~(isempty(obj.ExpectedNumVars) || length(newY0) == obj.ExpectedNumVars)
131131
error('Expected Y0 to have %d components but has %d', obj.ExpectedNumVars, length(newY0));

0 commit comments

Comments
 (0)