Using User-defined class' object in another user-defined class

I have define a class with name Function.m which it has super class of several subclass. I define another class with name Implementation.m which I need to access to each subclass properties of Function. I want to call Function as f in implementation file but I don't know how to do that I have post some of my class definition that it help you to understand my question better.
Classdef Sine_0_PiOver2 < Function %description = "Sin(x)on [0 PI/2["; methods function obj = Sine_0_PiOver2() obj.a = 0.0; obj.b = PI/2.0; obj.c = 0.0; obj.d = 1.0; obj.openInputInterval = true; obj.openOutputInterval = false; end function val_x = val(x) val_x = sin(x); end end end
classdef Function
properties
a;
b;
c;
d;
openInputInterval = false;
openOutputInterval = false;
knownMaxD2 = false;
maxD2;
end
methods
function impl = Implementation
end
function Error_In_Bits = ErrorInBits(error,impl,d,c)
Error_In_Bits = (error/(d-c))*impl.p2(impl.outputSize)*impl.outputScaling; end
function Correct_Bits = CorrectBits(error,d,c)
Correct_Bits = -log2(error/(d-c)); end
function BodyBuilding = power(a,b)
if b < 0
disp('Error in power');
elseif b == 0
BodyBuilding = 1;
else
BodyBuilding = (a*power(a,b-1));
end
end
function log_2 = log2(x)
log_2 = (log(x)/log(2));
end
end
end
classdef Implementation % This abstract class represents an implementation of the computation of % a function, on a certain interval. % @author Masoud Sadeghian properties % Verbosity level */ verbose = 0; % The function to be implemented */ % Function f; % Input size (in bits) */ inputSize; % Output size (in bits) */ outputSize; % The input range is 2^inputSize */ inputRange; % The output range is 2^outputSize */ outputRange; % In the case when the dicrete interval is open, this value will % be equal to 1. In the case when it is closed, it will be equal % to 2^n+1/2^n */ inputScaling; % In the case when the dicrete interval is open, this value will % be equal to 1. In the case when it is closed, it will be equal % to 2^n+1/2^n */ outputScaling; % The maximum total error (including rounding) */ maxError = 0; % The maximum methodological error (without rounding) */ maxMethodError = 0; % The target maximum error (the value of a half LSB) */ epsilonT = 0; end
methods
function obj = Implementation(verbose_,function_,inputSize_,outputSize_)
% The constructor sets up all the parameters */
verbose = verbose_;
f = function_;
inputSize = inputSize_;
outputSize = outputSize_;
inputRange = bitshift(1,inputSize); outputRange = bitshift(1,outputSize); if f.openInputInterval == false inputScaling = (inputRange - 1)/(inputRange) ; else inputScaling = 1.0 ; end if f.openOutputInterval == false outputScaling = (outputRange - 1)/(outputRange); else outputScaling = 1.0; epsilonT = (f.d-f.c)/(p2(inputSize+1)*outputScaling); end end
function f = Function
end
% Useful function*/
function p_2 = p2(a)
p_2 = pow(2.0, a);
end
% Useful function*/
function log_2 = log2(x)
log_2 = (log(x)/log(2));
end
% A few methods that convert numbers from the integer range
% to the real range, and conversly, for input or output */
function input_IntTo_Real = inputIntToReal(i)
input_IntTo_Real = f.a + ((f.b-f.a)*i)/((inputRange)*inputScaling);
end
function output_IntTo_Real = outputIntToReal(i)
output_IntTo_Real = f.c + ((f.d-f.c)*(i)/((outputRange)*outputScaling);
end
function input_RealTo_Int = inputRealToInt(x)
input_RealTo_Int = round((x-f.a) * (inputRange) * inputScaling/(f.b-f.a));
end
function output_RealTo_Int = outputRealToInt(y)
output_RealTo_Int = round((y-f.c) * (outputRange) * outputScaling/(f.d-f.c));
end
% This function computes the approximation without rounding */
function fpval(x)
end
% This function is the central function provided by this
% class. It compute an approximation of f, with an argument
% between 0 and InputRange-1, and returns a integer
% between 0 and outputRange-1 */
function val(x)
end
% This method takes its input in the real input interval, and
% returns a value in the real output interval. The value returned
% is exactly f.val */
function exactFPFPval(x)
f.val(x);
end
% This method takes its input in the integer input interval, and
% returns a value in the (real) output interval [0..outputRange[
% before rounding */
function exact_IINo_Round = exactIINoRound(i)
x = inputIntToReal(i);
y = f.val(x);
exact_IINo_Round = round((y-f.c) * (outputRange) * outputScaling/(f.d-f.c));
end
% This method takes its input in the integer input interval, and
% returns a value in the integer output interval */
function exact_IIval = exactIIval(i)
exact_IIval = round(exactIINoRound(i));
end
% This method takes its input in the integer input interval, and
% returns a value in the real output interval */
function y = exactIFPval(i)
x = inputIntToReal(i);
y = f.val(x);
end
% This method takes its input in the real input interval, and
% returns a value in the integer output interval */
function exact_FPIva = exactFPIval(x)
y = f.val(x);
exact_FPIva = outputRealToInt(y);
end
% Expresses an error in terms of least significant bit */
function error_InBits = errorInBits(error)
% we have 2^wo bits to represent the interval [c,d[
% The error lives in this interval.
% therefore it represents in bits:
error_InBits = error / (f.d-f.c) * outputRange * outputScaling;
end
% This procedure computes the maximum method error by
% enumeration over the whole interval [0, inputRange-1].
% If there is a quicker method, it should be implemented privately */
function maxMethodError = computeMaxMethodError()
maxerror = 0;
for i = 1 : inputRange
y0 = exactIFPval(i);
y = fpval(i);
error = abs(y-y0);
if (error > maxerror)
maxerror = error;
end
maxMethodError = maxerror;
end
end
% This procedure exhaustively checks that faithful rounding is
% obtained over the whole interval [0, inputRange-1] */
function exhaustiveCheck()
error = 0;
ierr = 0;
dierr = 0;
derror = 0;
for i = 1 : inputRange
y0 = (exactIFPval(i) - f.c) * (outputRange) * outputScaling / (f.d-f.c);
y = val(i);
dy = fpval(i);
deps = abs(dy-y0);
eps = abs(y-y0);
if eps > error
error = eps;
ierr = i;
end
if deps > derror
derror = deps;
dierr = i;
end
end
maxMethodError = derror;
maxError = error;
end
end
end

1 comentario

per isakson
per isakson el 27 de Abr. de 2014
Editada: per isakson el 27 de Abr. de 2014
You improve the chances to get an answer if you pose a concise question and attach the code in one or more files. Copy&paste of your question produces a mess.
And btw change
Classdef Sine_0_PiOver2 < Function
to
classdef Sine_0_PiOver2 < Function

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Preguntada:

el 25 de Abr. de 2014

Editada:

el 27 de Abr. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by