Comparing two equations with measured data
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Given two polynomial models Y= 3x^3 +4x^2 + 0.1x + 0.04 and Y2 = 2.5x^3 + 3.2x^2 + 0.5x - 0.1. Use the given measured data X={0.2, 0.6, 0.8, 0.9, 1}, Y={0.3, 0.65, 2.3, 0.5, 1.5}. Use MATLAB to fit the data with the given model. Provide residual plots for each and perform F-statistical analysis to determine which model provides better fits the measured data. I tried but was unsuccessfull.
plot(X,Y,'o')
model1= 3*x.^3 +4*x.^2 + 0.1*x + 0.04;
guess1=[1 1];
model2= 2.5*x.^3 + 3.2*x.^2 + 0.5*x - 0.1;
guess2=[1 1 ];
[alpha,R1,J1,CovB1,MSE1] = nlinfit(X,Y,model1, guess1);
[beta,R2,J2,CovB2,MSE2] = nlinfit(X,Y,model2, guess2);
x=linspace(2,18,1000);
ssmodel1=sum(R1.^2);
ssmodel2=sum(R2.^2);
sstotal=sum((X-mean(X)).^2);
r2model1=1-ssmodel1./sstotal;
r2model2=1-ssmodel2./sstotal;
F=ssmodel1./ssmodel2;
df=length(T)-2;
P=1-fcdf(F,df,df);
3 comentarios
the cyclist
el 4 de Dic. de 2021
@Kabit Kishore, in addition to the wise words of @Star Strider, be aware the you do not need to fit a non-linear function here (i.e. do not need nlinfit). When a model is described as "non-linear", it is referring to the coefficients, not the powers of the terms. So, for example
y = a*x^2 + b*x + c
is a linear model because it is linear in the coeffients a, b, and c; but
y = exp(d*x)
is non-linear, because it is not linear in the coefficient d.
I would recommend using the fitlm function. And read the documentation to see example of how to specify the fitting functions.
Ive J
el 8 de Dic. de 2021
As @the cyclist pointed out, your model is in fact linear (linear combination of predictors). But your question is not clear to me, because you've already two equations (fitted probably on another dataset), so you're not looking for coefficients, you already have them!
x = [0.2, 0.6, 0.8, 0.9, 1]; y = [0.3, 0.65, 2.3, 0.5, 1.5];
mdl1 = fitlm(x, y, 'y ~ x1^3 + x1^2 + x1')
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!