Effacer les filtres
Effacer les filtres

How to set a parameter of poly2 fit to a specific value during fit process?

8 vues (au cours des 30 derniers jours)
Alexandria Will-Cole
Alexandria Will-Cole le 20 Juil 2018
Commenté : dpb le 24 Juil 2018
I'm trying to take data and plot it then fit a curve that is of the form f(x) = p1*x^2 + p2*x + p3, but with p2 equal to zero. Right now my code fits for p1, p2, and p3. How can I set p2 to zero and allow it only to fit p1 and p3? Please see the code and results below. Thank you!
Code:
rho=Resistivityohmcm;
T=TemperatureK;
plot(T,rho,'-o')
f=fit(T,rho,'poly2');
plot(f,T,rho)
disp (f)
Results:
Gives the correct plot and the values for f:
Linear model Poly2:
f(x) = p1*x^2 + p2*x + p3
Coefficients (with 95% confidence bounds):
p1 = 1.511e-07 (1.422e-07, 1.599e-07)
p2 = -2.127e-05 (-2.512e-05, -1.743e-05)
p3 = 0.001779 (0.001383, 0.002175)

Réponse acceptée

dpb
dpb le 20 Juil 2018
Modifié(e) : dpb le 24 Juil 2018
You have to define the model...for something this simple the anonymous function route is the simplest...
fnPolySq = @(p1,p2,x) p1*x.^2 + p2;
f=fit(T,rho,'fnPolySq');
ADDENDUM
It's the pits getting old...forgot where I was going in mid-stream... :(
The above estimates the function without the linear term; the Q? was for a constant value...same idea, build it into the model
C=YourValue;
fnPolySq = @(p1,p3,x) p1*x.^2 + C*x + p3;
  5 commentaires
Alexandria Will-Cole
Alexandria Will-Cole le 24 Juil 2018
Thank you! This works very well! I appreciate it!
dpb
dpb le 24 Juil 2018
You could then Accept answer to indicate topic closed if nothing else...
Glad to help...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by