Traditional Culture Encyclopedia - Weather inquiry - What is the matlab program for least squares method?
What is the matlab program for least squares method?
I will give you an example of least squares fitting to experience for yourself:\x0d\The following is what is obtained from the weather forecast of Urumqi around 7:00 in the morning (Xinjiang time) in the past month Temperature data table, find any degree of curve fitting equation and its image according to the data.
\x0d\(October 26~November 26, 2008)\x0d\Number of days 1 2 3 4 5 6 7 8 9 10\x0d\Temperature 9 10 11 12 13 14 13 12 11 9\x0d\Number of days 11 12 13 14 15 16 17 18 19 20\x0d\Temperature 10 11 12 13 14 12 11 10 9 8\x0d\Days 21 22 23 24 25 26 27 28 29 30\x0d\Temperature 7 8 9 11 9 7 6 5 3 1\x0d \\x0d\The following uses Matlab programming to perform least squares fitting of the above data\x0d\Matlab program code: \x0d\x=;\x0d\a1=polyfit(x,y,3) %cubic polynomial fitting%\ x0d\a2= polyfit(x,y,9) %9th degree polynomial fitting%\x0d\a3= polyfit(x,y,15) %15th degree polynomial fitting%\x0d\b1= polyval(a1,x )\x0d\b2= polyval(a2,x)\x0d\b3= polyval(a3,x)\x0d\r1= sum((y-b1).^2) %Sum of squared errors of cubic polynomial%\x0d\r2 = sum((y-b2).^2) %Sum of square errors of polynomials of degree 9%\x0d\r3= sum((y-b3).^2) %Sum of square errors of polynomials of degree 15%\x0d\plot (x,y,'*') %Use * to draw the x,y image%\x0d\hold on\x0d\plot(x,b1, 'r') %Use the red line to draw the x,b1 image%\x0d \hold on\x0d\plot(x,b2, 'g') %Use green line to draw x,b2 image%\x0d\hold on\x0d\plot(x,b3, 'b:o') %Use blue Color o line draws x, b3 image%
- Related articles
- What are the places in Shanghai suitable for enjoying autumn?
- Fresh milk (pasteurized milk (how long can it be stored at room temperature)? Now my weather is 10 degrees ... can I stay here 24 hours?
- What should I pay attention to when traveling to Jiuhua Mountain?
- Weining West Sea Travel Guide Weining Travel Route
- How does the weather affect the paint?
- The weather before Yongzhou 15
- How many kilometers is it from Yongkang to Haining?
- An essay describing the four seasons in Huangshan Mountain.
- What are the winter solstice songs?
- What are the breathing skills for long-distance running (800 m1000 m)?