I'm going to use bitsra() function to perform arithmetic shift right operation. But Matlab interpret thinks my script erroneous. The manual from Mathworks keep silent on this issue. I'm sorry about having posted my entire code, But when I pull out the part of erroneous code from the entire code and then I get the interpreter to execute error part, it works. I don't know why this error occurs. you may see erroneous part in entire code that marks as "% error error error".
% x^3 + 4x^2 - 10
% linear approximation f(x)=f(x0)+f'(x0)(x-x0) at x=x0
function [ y ] = polynomial( x, scale_factor ) % x is scaled by scale_factor.
% POLYNOMIAL Summary of this function goes here
% Detailed explanation goes here
% determine x0 near x.
if( x > int16(1.5 * scale_factor) )
x0 = int16(1.75 * 4); % set x0 to 1.75 if x is between 1.5 and 2
else
x0 = int16(1.25 * 4); % set x0 to 1.25 if x is between 1 and 1.5
end
x0_square = int16(x0 .* x0); % scale factor : 2^4
x0_square_11 = x0_square .* 2.^7; % this variable is scaled by 2^11.
x_10 = int16(x);
x_10 = bitsra(x_10, 1); % scale factor : 2^10
x0_10 = x0 .* 2.^8; % scale factor : 2^10
% linear approximation of x square near x0
% should be 11 1 10
x_square_a = int16( x0_square_11 + ( bitsra(2 .* x0, 1) .* (x_10 - x0_10) )); % scale_factor : 2^11
% error error error
x_9 = bistra(x_10, 1); % scale factor : 2^9
x0_9 = bitsra(x0_10, 1); % scale factor : 2^9
x0_cubic = int16( x0_square .* x0); % scale factor : 2^6
x0_cubic_13 = x0_cubic .* 2.^7; % scale factor : 2^11
% linear approximation of x cubic near x0
% 13 4 9
x_cubic_a = int16(x0_cubic_13 + ( ((3 .* x0_square) .* (x_9 - x0_9)) ));
x_cubic_a = bitsra(x_cubic_a, 2); % scale factor : 2^11
constant_term = int16( 10 .* scale_factor);
y = int16( x_cubic_a + 4 .* x_square_a - constant_term );
end
Matlab gives
Undefined function 'bistra' for input arguments of type 'int16'.
Error in polynomial (line 30)
x_9 = bistra(x_10, 1); % scale factor : 2^9