Commit a997acc2 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete: revised plot & solveAlgebraic

parent 996e8bb1
......@@ -273,7 +273,7 @@ classdef Odes < handle & matlab.mixin.Copyable
myOdeString = myOdeString + " + " + misc.latexChar(obj.ss{1}.B) + thisInputName;
end
end
myOutputString = thisOutputName + "(t) &= ";
myOutputString = thisOutputName + "&= ";
plusNeeded = false;
if any(obj.ss{1}.C ~= 0)
if misc.iseye(obj.ss{1}.C)
......
......@@ -368,7 +368,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% *) build a new valueDiscrete on the correct grid.
obj_hat = quantity.Discrete( newValues, tmpDomain.join, ...
'name', obj.name + "°" + g.name);
'name', obj.name + " ° " + g.name);
end % compose()
......@@ -846,7 +846,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
K.setName("kron(" + xName + ", " + yName + ")");
end % kron()
function solution = solveAlgebraic(obj, rhs, findBetween)
function solution = solveAlgebraic(obj, rhs)
% solveAlgebraic solves
% obj( x ) == rhs
% for the variable specified x.
......@@ -856,22 +856,10 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
arguments
obj (1, 1);
rhs (1, 1) double;
findBetween double = [];
end
assert(obj(1).nargin == 1, "only implemented for quantites on 1 domain");
% if nargin > 2
% assert(numel(findBetween)==2, "a lower and upper limit must be specified (or neither)");
%
% objValueTemp = obj.on();
% gridSelector = (objValueTemp >= findBetween(1)) & (objValueTemp <= findBetween(2));
% gridSelector([max(1, find(gridSelector, 1, 'first')-1), ...
% min(find(gridSelector, 1, 'last')+1, numel(gridSelector))]) = 1;
%
% solution = interp1(objValueTemp(gridSelector), obj.domain.grid(gridSelector), rhs);
% else
solution = interp1(obj.on(), obj.domain.grid, rhs);
% end
solution = interp1(obj.on(), obj.domain.grid, rhs);
end % solveAlgebraic()
......@@ -1118,7 +1106,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% FIXME: check if all funtions in this object have the same
% number of input values.
n = numel(obj(1).domain);
end
end % nargin
% function d = gridDiff(obj)
%
......@@ -1176,13 +1164,13 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
subplotRowIdx = 1:size(obj, 1);
subpotColumnIdx = 1:size(obj, 2);
i = 1: numel(obj(:,:,figureIdx));
i = reshape(i, size(obj, 2), size(obj, 1))';
idx = 1 : numel(obj(:,:,figureIdx));
idx = reshape(idx, size(obj, 2), size(obj, 1))';
for rowIdx = subplotRowIdx
for columnIdx = subpotColumnIdx
if ~p.Results.currentFigure
subplot(size(obj, 1), size(obj, 2), i(rowIdx, columnIdx));
subplot(size(obj, 1), size(obj, 2), idx(rowIdx, columnIdx));
end
if p.Results.hold
hold on;
......@@ -1244,27 +1232,24 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
myTitle = "$${[" + greek2tex(obj(rowIdx, columnIdx, figureIdx).name) ...
+ "]}_{" + num2str(rowIdx) + num2str(columnIdx) + num2str(figureIdx) + "}$$";
end
if strlength(myTitle) > 20
myTitle = split(myTitle);
if numel(myTitle) > 2
myTitle = myTitle(1) + " [\ldots] " + myTitle(end);
end
end
end % titleHelper()
function myText = greek2tex(myText)
if ~contains(myText, "\")
myText = strrep(myText, "Lambda", "\Lambda");
myText = strrep(myText, "lambda", "\lambda");
myText = strrep(myText, "Zeta", "\Zeta");
myText = strrep(myText, "zeta", "\zeta");
myText = strrep(myText, "Gamma", "\Gamma");
myText = strrep(myText, "gamma", "\gamma");
myText = strrep(myText, "psi", "\psi");
myText = strrep(myText, "phi", "\phi");
myText = strrep(myText, "Psi", "\Psi");
myText = strrep(myText, "Phi", "\Phi");
myText = strrep(myText, "Delta", "\Delta");
myText = strrep(myText, "delta", "\delta");
myText = strrep(myText, "°", " \circ ");
if ~contains(myText, "\zeta") && ~contains(myText, "\Zeta")
myText = strrep(myText, "eta", "\eta");
end
myText = strrep(myText, "pi", "\pi");
myText = strrep(myText, "Pi", "\Pi");
oldStr = ["alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", ...
"theta", "vartheta", "iota", "kappa", "lambda", "mu", "nu", "xi", "pi", ...
"rho", "sigma", "varsigma", "tau", "phi", "chi", "psi", "omega", ...
"Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "\Upsilon", ...
"Phi", "Psi", "Omega"];
newStr = "\" + oldStr + " ";
oldStr = [oldStr, " ° "];
newStr = [newStr, " \circ "];
myText = replace(myText, oldStr, newStr);
end
end % greek2tex()
end % plot()
......@@ -2423,7 +2408,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% create result object
C = quantity.Discrete(aDiscrete + bDiscrete, joinedDomain, ...
'name', A(1).name + "+" + B(1).name);
end
end % plus
function C = minus(A, B)
% minus uses plus()
......
......@@ -260,7 +260,7 @@ classdef Symbolic < quantity.Function
end
end % subsNumeric()
function solution = solveAlgebraic(obj, rhs, findBetween)
function solution = solveAlgebraic(obj, rhs)
% solveAlgebraic solves
% obj( x ) == rhs
% for the variable specified x.
......@@ -270,7 +270,6 @@ classdef Symbolic < quantity.Function
arguments
obj (1, 1);
rhs (1, 1) double;
findBetween double = [];
end
assert(obj(1).nargin == 1, "only implemented for quantites on 1 domain");
......
......@@ -1092,11 +1092,6 @@ X = quantity.Domain("x", linspace(0,1,11));
fScalar = quantity.Symbolic([(1+x)^2], X);
solutionScalar = fScalar.solveAlgebraic(2);
testCase.verifyEqual(solutionScalar, sqrt(2)-1, "AbsTol", 1e-12);
% % array
% f = quantity.Symbolic([2*x, 1], X);
% solution = f.solveAlgebraic([1, 1], f(1).domain(1).name);
% testCase.verifyEqual(solution, 0.5);
end
function testSubs3(tc)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment