フィルターのクリア

Trying to find the roots of polynomial with a script file

2 ビュー (過去 30 日間)
Go Detroit Lions
Go Detroit Lions 2018 年 10 月 4 日
回答済み: Image Analyst 2018 年 10 月 11 日
function [y] = Func_6_23(x)
y = ((x^5) - (12*(x^4)) - (9*(x^3)) + (392(x^2)) - (372*x) - 2160);
end
I'm trying to execute this script file to find roots and I keep getting this error,
Error in roots (line 26) when I don't even have a line 26.
if ~all(isfinite(c))
  5 件のコメント
Go Detroit Lions
Go Detroit Lions 2018 年 10 月 4 日
編集済み: Walter Roberson 2018 年 10 月 4 日
The assignment stated to:
Use MATLAB's roots function, write a script M-file to find the roots of the polynomial. State the commands of the script file you used.
I found an error in the file i wrote, (392(x^2))-->(392*(x^2)) but still gives the same error, so I'll try to fix it later. Thanks for your help.
Walter Roberson
Walter Roberson 2018 年 10 月 4 日
hint: the roots of 10*x^3 - 7*x^2 - 11*x + 4 can be found by roots([10, 7, 11, 4])

サインインしてコメントする。

回答 (2 件)

madhan ravi
madhan ravi 2018 年 10 月 4 日
y=[1 -12 -9 392 -372 -2160]
roots(y)
Note: Always use coefficients to find roots in Matlab.
  1 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 11 日
If it worked , accept the answer

サインインしてコメントする。


Image Analyst
Image Analyst 2018 年 10 月 11 日
"My professor called it from the command line with the following text: roots(@Func_6_23)"
It seems like your professor wants a function from you that determines (returns) a vector with the polynomial coefficients, which you can then pass in to the built-in roots() function. It might go something like:
function [y] = Func_6_23(inputPolynomial)
% For example inputPolynomial is a string "((x^5) - (12*(x^4)) - (9*(x^3)) + (392(x^2)) - (372*x) - 2160);"
% and we're supposed to return y as [1, 12, 9, 392, 372, -2160]
inputPolynomial(inputPolynomial== ' ') = []; % Remove any spaces.
% Now loop over orders, say the first 20 or whatever and find 'x^n'
for k = 1 : 20
thisString = sprintf('x^%d', k); % E.g. 'x^5'
index = strfind(inputPolynomial, thisString); % Find x^5 in the whole polynomial string.
% etc. to find coefficients of thisString.
y(k) = .....
end
% Here, you should have y which is a vector containing all the coefficients,
% which you can then pass in to roots().

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by