我将使用bitsra()
函数来执行算术右移操作。但是 Matlab 解释认为我的脚本是错误的。Mathworks 的手册对此问题保持沉默。我很抱歉发布了我的整个代码,但是当我从整个代码中提取错误代码的一部分,然后让解释器执行错误部分时,它就可以工作了。我不知道为什么会出现这个错误。您可能会在整个代码中看到标记为“% 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给出
Undefined function 'bistra' for input arguments of type 'int16'.
Error in polynomial (line 30)
x_9 = bistra(x_10, 1); % scale factor : 2^9