# How to determine polynomial coeffisient of N x M matrix instead Of 1 x N or N x 1?

조회 수: 1(최근 30일)
Tyann Hardyn 2021년 9월 8일
댓글: Tyann Hardyn 2021년 9월 8일
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....

댓글을 달려면 로그인하십시오.

### 채택된 답변

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)
c = 1×3
1.0023 2.9467 5.2131
This looks pretty close to [1 3 5] to me.
##### 댓글 수: 1표시숨기기 없음
Tyann Hardyn 2021년 9월 8일
Ahh, yes, Sir, i want to create one Polynomial from all of my Matrix Data.
And how to do for "One Per Row" Polynomial?
A = magic(5);
B = A.^2 + 3*A + 5 + randn(size(A)); % Adding a little noise
c = polyfit(A(:), B(:), 2)
Is this for one polynomial from all of my matrix data?

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by