Commit c061b3fa by Ferdinand Fischer

### Added plot section to the example file, more detailed description of numeric...

Added plot section to the example file, more detailed description of numeric data access and some minor issues
parent 310c95cf
 ... ... @@ -1313,6 +1313,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ... % b(z) = a(1-z) = a.flipDomain('z'); % or for the multidimensional case with c(z, zeta) % d(z, zeta) = c(1-z, 1-zeta) = c.flipDomain(["z", "zeta"]; % if z and zeta are domains on (0,1). arguments obj myDomainName string ... ...
 ... ... @@ -10,7 +10,7 @@ z = quantity.Domain("z", linspace(0, 1, 101)) % "name" : the name given "z" % "n" : the number of grid points numel(z.grid) = 101 % "lower" : the lower boundary of z = 0 % "upper" : the upper boundary of z = 0 % "upper" : the upper boundary of z = 1 % Then we can create a(z) = 1 + z using numerical data and this domain z: a = quantity.Discrete(... ... ... @@ -23,23 +23,31 @@ a = quantity.Discrete(... % verify that a(z) is the desired variable by plotting it: a.plot(); %% Access to numerical data using the method on() % verify that a(z) = 1 + z by evaluating it for different points in z = 0, 0.5, 1: [a.on(0), a.on(0.5), a.on(1)] % or more compact: a.on([0, 0.5, 1]) % on(gridValues) performs an interpolation, when the specified values do not lie on % the grid a.grid, for instance a.on(0.1234567123123123); % on() without any input arguments returns the original data, %% Access to numerical data % to access the numerical three methods are provided: % The first is the method a.on(). If it is called without an argument it returns the original data: isequal(a.on(), 1+z.grid); % additionally, on can be called using quantity.Domain objects. Sampling a with 3 discrete points: zSample = quantity.Domain("z", linspace(0, 1, 3)); % the new domain must have the same name as the % domain of a. a.on(zSample) % on(gridValues) performs an interpolation, when the specified values do not lie on % the grid a.grid, for instance a.on(0.1234567123123123); % the second method to access the numeric data is to use the "at" method: a.at(0) % only single points can be specified. This is advantangeous if a would be a matrix valued function. % verify that a(z) = 1 + z by evaluating it for different points in z = 0, 0.5, 1: [a.at(0), a.at(0.5), a.at(1)] % or more compact: a.on([0, 0.5, 1]) % the third method to access the numeric data is to use the index. Evaluation of the first and the % last point would be: a.atIndex(1) a.atIndex(end) %% Lets do some basic math operations % spatial derivatives ... ... @@ -51,10 +59,10 @@ plot([a; a_dz; a_dzz]); % note: as the derivative is implemented numerically usi % gradient method, numerical errors occur. % plus and minus aPlus1 = a + 1; TwoMinusA = 2-a; twoMinusA = 2-a; % note that quantites can be concatenated using [ ... ] or the methods vertcat, horzcat or cat. aaa = [a; aPlus1; TwoMinusA]; aaa = [a; aPlus1; twoMinusA]; plot(aaa); %% Sustitution: b = a(zeta) ... ... @@ -93,6 +101,12 @@ misc.subsurf(cDisc, "xLabel", "z", "yLabel", "\zeta", "myTitle", "c"); % the second dimension j should represent z, this can be achieved using the domains: cDisc = c.on([zetaSample, zSample]); % to evaluate a function c(z,zeta) pointwise z1 = 0.19; zeta1 = 0.29; c.at({z1, zeta1}) %can be used %% Substitution: of multidimensional data c(z, zeta) % use subs to replace variables z or zeta with a constant value, for instance, % c2(zeta) = c(0.25, zeta) ... ... @@ -145,6 +159,25 @@ y = x + cumInt(K*x.subs("z", "zeta"), "zeta", 0, "z"); % 4. input: upper bound of integral 'z' y.plot(); %% plotting of quantities % As have been shown, quantities can be displayed by the plot method. For each quantity a new window % is opened and each entry of a matrix valued quantity is plotted into a own subplot. To specifiy % which figure should be used for a plot the optional name-value-pair argument "fig" can be used: a.plot("fig", 1) % will plot quantity a into figure 1. If a second quantity should be plotted into the same window, % the optional name-value-pair "hold" can be used: a_dz.plot("fig", 1, "hold", true) % will plot first derivative of a into the same figure. % To use the subplot to display different quantities, use the "currentFigure" optional % name-value-argument: figure(1); clf; subplot(211); c.plot("currentFigure", true); % with this argument combined with the "hold" option, all entries of a matrix valued quantity can be % composed into one axis: subplot(212); aaa.plot("currentFigure", true, "hold", true) %% Commonly used methods % Similar to many matlab built-in methods the following operations are supported: % - math opertions: mtimes, inv, exp, expm, log, log10, sqrt, sqrtm, uminus, prod, sum, power, ... ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!