Creating equation gives error using fit function.

1 次查看(过去 30 天)
Hello,
I'm trying to make an equation from data with fit function. In a data it seems like a straight line and what I'm expecting in my equation.but not sure why it give me larger error. It gives me a coefficient of the equation which is not fitting to my data sets.
Is there any another function that can help me to set a data sets and getting coefficient of the equation?
I'm trying wih the available data and I divide column as per requirement and I'm ploting column 13 Vs. 22. I expecting same results as in the column 14. But it's deviating.
load trial_hand_fixing.txt
h_DC_SPHERE_250_G1_R8 = trial_hand_fixing(:,4);
h_delta_DC_SPHERE_250_G1_R8= trial_hand_fixing(:,22);
k_DC_SPHERE_250_G1_R8 = trial_hand_fixing(:,13);
g_DC_SPHERE_250_G1_R8 = trial_hand_fixing(:,15);
w_DC_SPHERE_250_G1_R8 = trial_hand_fixing(:,16);
m_DC_SPHERE_250_G1_R8 = trial_hand_fixing(:,17);
k_w_DC_SPHERE_250_G1_R8 = trial_hand_fixing(:,19);
u50_DC_SPHERE_250_G1_R8 = trial_hand_fixing(:,5);
u50_corrected_DC_SPHERE_250_G1_R8 = trial_hand_fixing(:,14);
temp_DC_SPHERE_250_G1_R8= trial_hand_fixing(:,2);
x=h_delta_DC_SPHERE_250_G1_R8;
x1=h_delta_DC_SPHERE_250_G1_R8-11;
y=k_DC_SPHERE_250_G1_R8;
f=fit(x1,y,'poly3') %using poly3 fir function for the calculating coefficient
y_est = f.p1*x1.^3 + f.p2*x1.^2 + f.p3*x1 + f.p4;
plot(x1, y , 'b-', x1, y_est, 'r-', 'LineWidth', 1)
xlabel('h/delta')
ylabel('k')
legend('real','polynominal3')
axis square
title('DC SPHERE 500 G04 2 POLY3')
error= y_est-y;
rmse= sqrt(mean(error.^2))
  2 个评论
Monica Roberts
Monica Roberts 2022-5-6
It looks like fit is doing an okay job here. It's a bit more clear if you plot with markers instead of lines:
plot(x1, y , 'bx', x1, y_est, 'ro', 'LineWidth', 1)
There is a larger deviation in the data on the left side so the majority of the error is coming from there.
Nilanshu Mahant
Nilanshu Mahant 2022-5-7
编辑:Nilanshu Mahant 2022-5-8
But, then it give me larger error while I'm creating equation from this. As I have a different flow chart of equation. Is it possible to make equation using regression learner. I'm creating model gaussian regression matern 5/2 GPR. How can I get the equation from the this trained model. I'm selecting pressure, temperature, humidity as input and trying to get some output. The y estimated values from the trainedmodel is fitting good. But, Now I want to make equation from this model and how can I make that?
I want to find coefficient for gaussian equation.

请先登录,再进行评论。

回答(1 个)

Nipun
Nipun 2023-12-29
Hi Nilanshu,
I understand that you are trying to retrieve the polynomial equation from the "fit" function in MATLAB.
On analyzing your code, I notice that you are fitting the data using a third degree polynomial regression
f=fit(x1,y,'poly3') %using poly3 fir function for the calculating coefficient
The coefficients can be accessed using "coeffvalues" function on the "cfit" object as under:
coeff_array = coeffvalues(f);
Here, "coeff_array" represents the array of coefficients. For instance to get the second coefficient "p2", do the following
p2 = coeff_array(2);
Hope this helps.
Regards,
Nipun

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by