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 CenterFile Exchange에서 R Language에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by