Predict y values from x values
Afficher commentaires plus anciens
If x=[0 1 2 3 4 5]; and y=[0 20 60 68 77 110]; To get a linear equation I can use coefficients=polyfit(x,y,1) which gives me coefficients 20.8286 3.7619 so my linear equation is y = 20.8286 x + 3.7619 If I want to find an unknown y value from a known x value e.g. 1.5 I can use y=polyval(coefficients, 1.5) and I get y = 35.0048. In other words, using polyval, and using the equation derived from polyfit, when x = 1.5, y = 35.0048.
However, if I want to find an unknown x value from a known y value, what do I do?
Kind regards, Wendy
Réponse acceptée
Plus de réponses (1)
"Predict y values from x values"
>> x = [0,1,2,3,4,5];
>> y = [0,20,60,68,77,110];
>> ynew = 35;
>> xnew = interp1(y,x,ynew)
xnew = 1.3750
You can see how this value actually fits into your data:
>> plot(x,y,'-',xnew,ynew,'*')

1 commentaire
Wendy Cameron
le 30 Août 2018
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!