Polynoom coëfficiënt from excel data
1 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!