
plot a curved line of best fit through my data
    31 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
I have the following discrete points

if i use polyfit with a n = 2 it plots the line shown in the data that is not a good fit of the data. ideally i want a smooth curve between the data that i can then take the equation of to interpolate the values inbetween.
thanks!
0 Kommentare
Antworten (1)
  dpb
      
      
 am 25 Jun. 2018
        
      Bearbeitet: dpb
      
      
 am 25 Jun. 2018
  
      
Post the data points, but the red line is clearly NOT the least-squares quadratic through the blue points; something is amiss.
If I use estimates of
>> den=[320 500 830]; dep=[0 -20 -110];
>> figure
>> plot(den,dep,'o')
>> b=polyfit(den,dep,2)
b =
   -0.0003    0.1487  -15.1476
>> denfit=linspace(den(1),den(end));yhat=polyval(b,denfit);
>> hold on
>> plot(denfit,yhat,'r-')
>>
A quadratic will fit three points exactly.
To get a smooth curve, you have to evaluate at more than just the three points, but in your plot, the values aren't correct for those points.
Show your work so we can see where the mishap occurred...
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Interpolation finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

