
How to find a figure of polynomial curve fitting for 3 matrices
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have 3 matrices(mat1, mat2, mat3) and i found their averages one by one, and now i want to find their best polynomial curve fitting for each matrix(for each matrix should have 1 figrue of its polynomial curve fitting) by using X, average of (mat1, mat2 and mat3) and X2(X2 can be changable to suit for the best curve) as written in the codes bellow.
I'm able to do for 1 matrix but need help to do for 3 matrices
Many thanks in advance
clc
clear
X = [1 2 3];
mat1= [7 12 177;
0 10 7;
12 0 55];
mat2= [3 6 21;
0 4 3;
6 0 8];
mat3= [2 4 61;
0 3 2;
4 0 19];
Y = mean(mat1)
Y1 = mean(mat2)
Y2 = mean(mat3)
coefs = polyfit(X,Y,4);
X2= 1:0.1:3;
curve = polyval(coefs,X2);
plot(X2, curve, X, Y);
xlabel('x axis');
ylabel('y axis');
title('x and y');
0 Commenti
Risposte (1)
Dev
il 26 Ago 2025 alle 10:08
To plot the best polynomial curve for each matrix, we can modify the code provided in the question to use 2nd degree polynomials instead of 4th degree. Since we only have 3 data points, making 2nd degree more appropriate. Please find the updated code snippet below-
coefs = polyfit(X, Y1, 2); % Using 2nd degree polynomial
We can then use the “subplot” function along with the “figure” function to split our plots accordingly and plot all the three curves simultaneously.
I have attached an example figure after plotting all the three functions for your reference-

For more information on the usage of the functions mentioned above, please refer to the following links-
I hope the above explanation solves the question.
0 Commenti
Vedere anche
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!