How to determine polynomial coeffisient of N x M matrix instead Of 1 x N or N x 1?
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I wanna ask about how to use Polyfit Function or the other function in Matlab with a Matrix N x M.
If we use a 1 x N or N x 1 matrix, we can just input the data inside the Polyfit function and by using Polyval, it can be easily create an ouput of polynomial coefficient. For example :
orde = 2
x = [2:2:12]; %Declare an Independent Variable
y = [3.9572, 4.4854, 5.8003, 6.1419, 7.4218, 8.9157]; %Declare a dependent Variablecoefficient = polyfit(x, y, masukkan);
xc = [2:0.0001:12]; %Declare a data of fitting line to be plotted
coefficient = polyfit(x, y, orde);
yfit = polyval(coefficient, xc);
yc = polyval(coefficient, x); %Getting the output of xc by using polyval
%The output will become like this :
% Polinomial Polyfit : (0.0209)x^2 + (0.1919)x^1 + (3.5075)
%The coeffisient of polynomial on the above matrix is [0.0209, 0.1919,
%3.5075]
%Because we re using orde 2 of matrix
However, if i create a matrix with N x M dimension, we have to create an inversion by using Gaussian method, right?
So i have these datas :
x_kernel = rand(20, 15); %Synt Kernel Matrix M x N (20 x 15);
y_kernel = rand(20, 15); %Synt Kernel Matrix M x N (20 x 15);
% By using this formula :
% m = (G^T x G)^-1 x G^T x d,
% where m is coeffisient of polynomial [a, b, c, etc...]
% We can get the coeffisient of polynomial
And my question is, how to get polynomial coeffisien of those matrix kernels (x_kernel and y_kernel ) by using matlab 's function (maybe vandermonde matrix, polyfit, polyval, etc) So then we can plot the data by using x_kernel / y_kernel input versus the result of their polynomial equation?
Thank you very much, everyone...
Actually, this is one of my homework from my college, so iam so grateful if someone can tell me how to do that....
0 个评论
采纳的回答
Steven Lord
2021-9-8
Do you want M polynomials, one per row, or do you want one polynomial for all your data? If the latter, just columnize your data.
A = magic(5);
B = A.^2 + 3*A + 5 + randn(size(A)); % Adding a little noise
c = polyfit(A(:), B(:), 2)
This looks pretty close to [1 3 5] to me.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!