フィルターのクリア

Polynoom coëfficiënt from excel data

1 回表示 (過去 30 日間)
Armando Marchena
Armando Marchena 2015 年 10 月 17 日
コメント済み: Star Strider 2015 年 10 月 17 日
In order to calculate a parameters in a 5th order Polynoom function, im using "fzero" in a function. The input data is from an excel list (code shown below). I would like to function to work with any data inputted from an excel sheet.
function y = Cp_REV02(~)
%clear
%clc
cp_data = xlsread('Data.xlsx', 'testing', 'P7:P44')
f = @(x)- 0.0006*x.^5 + 0.0104*x.^4 - 0.0602*x.^3 + 0.146*x.^2 - 0.108*x + 0.043 -cp_data;
init_guess = 3;
lambda = fzero(f, init_guess)
end
The error is shown below:
Operands to the and && operators must be convertible to logical scalar values.
Error in fzero (line 307) elseif ~isfinite(fx) ~isreal(fx)
Error in Cp_REV02 (line 9) lambda = fzero(f, init_guess)

採用された回答

Star Strider
Star Strider 2015 年 10 月 17 日
To get the roots (zeros) of a polynomial, the easiest way is to use the roots function.
For instance:
cp_data = 1:5; % Create Data
for k1 = 1:length(cp_data)
p = [0.0006 +0.0104 -0.0602 +0.146 -0.108 +(0.043 - cp_data(k1))]; % Polynomial
r = roots(p); % All Roots
real_roots(:,k1) = r(imag(r)==0); % Real Roots
end
The fzero function only returns real roots, so I selected to retain only those. (If you want all of them, save ‘r’ instead of ‘real_roots’.) I used a cell array for ‘real_roots’ since the number of those may vary, depending on what ‘dp_data’ is in a particular iteration.
  8 件のコメント
Armando Marchena
Armando Marchena 2015 年 10 月 17 日
I get it now. It also reads the input as variables and not as a single number It works indeed with my excel sheet. Thank you very much :)
Star Strider
Star Strider 2015 年 10 月 17 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Functions in Microsoft Excel についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by