How can I fix the error in the given code? About 'inline'

6 ビュー (過去 30 日間)
Farhan Marco
Farhan Marco 2019 年 5 月 17 日
回答済み: Guillaume 2019 年 5 月 17 日
it_count=0;
xn=0;
if 0 >= 0.9
disp('0 < 3 is not true. Stop!')
root=NaN;
return
end
a = 0.9; b = 1.2;
f=inline('x^5 – 3*x^4 + 4*x^3 – 4*x^2 + 3*x – 1');
fa = feval(f,a); fb = feval(f,b);
The error statement:
Error using inlineeval (line 14)
Error in inline expression ==> x^5 – 3*x^4 + 4*x^3 – 4*x^2 + 3*x – 1
Error: Invalid text character. Check for unsupported symbol, invisible character, or pasting of non-ASCII characters.
Error in inline/feval (line 33)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
Error in bisect (line 37)
fa = feval(f,a); fb = feval(f,b);
Can anyone help me with the error?

回答 (1 件)

Guillaume
Guillaume 2019 年 5 月 17 日
As pointed out by Stephen, inline is deprecated, due to be removed soon from matlab. You'd be better off using an anonymous function:
f = @(x) x^5 - 3*x^4 + 4*x^3 - 4*x^2 + 3*x - 1
or even better
f = @(x) polyval([1, -3, 4, -4, 3, -1], x);
As for the reason for the error you see, it's because the - sign in your expression are not actual - characters but unicode character en dash (U+2013 or as decimal character code 8211). While they may look the same, they're completely different characters.

Community Treasure Hunt

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

Start Hunting!

Translated by