0
我打算使用bitsra()
函數來執行算術右移操作。但是Matlab解釋認爲我的腳本錯誤。 Mathworks的手冊在這個問題上保持沉默。我很抱歉發佈了我的整個代碼,但是當我從整個代碼中提取錯誤代碼的一部分,然後讓解釋器執行錯誤部分時,它就可以工作。我不知道爲什麼會發生此錯誤。您可能會在標記爲「%error error error」的整個代碼中看到錯誤的部分。爲什麼在Matlab語法錯誤?
% 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
我是笨蛋... – inherithandle