Curve Fitting in .NET framework

Creator QR Code in .NET framework Curve Fitting

CHAPTER 10 Curve Fitting
Making QR-Code In .NET
Using Barcode maker for .NET framework Control to generate, create QR Code JIS X 0510 image in Visual Studio .NET applications.
Reading QR Code In .NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET applications.
Temperature of cooling block 300 250 Temp(F) 200 150 100 0 1 2 3 Time(h) 4 5 6 7
Generate Barcode In Visual Studio .NET
Using Barcode drawer for .NET Control to generate, create barcode image in Visual Studio .NET applications.
Barcode Scanner In .NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in VS .NET applications.
Figure 10-5
Quick Response Code Generator In Visual C#.NET
Using Barcode printer for .NET Control to generate, create QR Code 2d barcode image in VS .NET applications.
Creating QR Code JIS X 0510 In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
A plot of temperatures for a cooling metal block
QR-Code Maker In Visual Basic .NET
Using Barcode drawer for .NET Control to generate, create Quick Response Code image in VS .NET applications.
Universal Product Code Version A Creator In Visual Studio .NET
Using Barcode drawer for VS .NET Control to generate, create UPC-A Supplement 2 image in VS .NET applications.
Let s create data for the time axis:
GS1 DataBar Expanded Creator In Visual Studio .NET
Using Barcode encoder for .NET Control to generate, create GS1 DataBar Expanded image in .NET framework applications.
Matrix 2D Barcode Printer In .NET
Using Barcode creator for VS .NET Control to generate, create 2D Barcode image in .NET applications.
>> t = linspace(0,7);
EAN / UCC - 14 Generation In VS .NET
Using Barcode encoder for VS .NET Control to generate, create GTIN - 128 image in .NET applications.
Create Code 2/5 In VS .NET
Using Barcode drawer for VS .NET Control to generate, create 2/5 Standard image in Visual Studio .NET applications.
Next define the fit function:
UPCA Drawer In Java
Using Barcode encoder for Java Control to generate, create UPC-A image in Java applications.
Code 39 Extended Recognizer In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
>> y = a*t^3 + b*t^2 + c*t + d;
Draw EAN / UCC - 14 In Java
Using Barcode creator for BIRT reports Control to generate, create GTIN - 128 image in BIRT reports applications.
ECC200 Generation In None
Using Barcode creator for Excel Control to generate, create Data Matrix ECC200 image in Office Excel applications.
We will also need an array of data evaluated at the exact time points where the temperature data was collected:
Bar Code Creator In Visual Basic .NET
Using Barcode printer for VS .NET Control to generate, create bar code image in .NET framework applications.
GTIN - 128 Generator In None
Using Barcode encoder for Font Control to generate, create EAN 128 image in Font applications.
>> w = a*time^3 + b*time^2 + c*time + d;
UCC - 12 Encoder In VB.NET
Using Barcode maker for .NET framework Control to generate, create UCC.EAN - 128 image in .NET applications.
Making DataMatrix In Java
Using Barcode maker for Java Control to generate, create Data Matrix image in Java applications.
Let s plot the collected data and the fit curve on the same graph:
>> plot(time,temp,'o',t,y),xlabel('time(h)'),ylabel ('temp(F)'),title('Third Order fit for cooling metal block')
The result is shown in Figure 10-6 It looks like the third order polynomial has generated a good fit Let s compute r2 First we find the mean of the collected data and calculate S:
>> M1 = mean(temp) M1 = 2082308 >> S = sum((temp M1)^2) S = 32542e+004
MATLAB Demysti ed
Third order fit for cooling metal block 400 Temp(F) 300 200 100
3 Time(h)
Figure 10-6
Plot of a third order polynomial fit
Now let s find A:
>> A = sum((w temp)^2) A = 279327677455582
We find r2 to be:
>> r2 = 1 A/S r2 = 10000
It looks like we have a perfect fit to the data However this is misleading and in fact the real function describing this data is: T = 100 + 20259e 023t 259e 180t Let s have MATLAB print the r-squared value in long format:
>> format long >> r2 r2 = 099991416476050
CHAPTER 10 Curve Fitting
Well, the fit is extremely accurate as you can see from the plot Let s compute the RMS
>> RMS = sqrt(sum((1/N)*(w temp)^2)) RMS = 046353796413735
The RMS is less than one, so we can take it to be a good approximation Now that we have a function y(t), we can estimate the temperature at various times for which we have no data For instance, the data is collected out to a time of 7 hours Let s build the function out to longer times First we extend the time line:
>> t = [0:01:15];
Regenerate the fit polynomial:
>> y = a*t^3 + b*t^2 + c*t + d;
We can use the find command to ask questions about the data For instance, when is the temperature less than 80 degrees, so maybe we can risk picking up the metal block
>> find(y < 80) ans = 148 149 150 151
The command find has returned the array indices for temperatures that satisfy this requirement We can reference these locations in the array t that contains the times and the array y that contains the temperatures First we extract the times, adding a quote mark at the end to transpose the data into a column vector:
>> A = t(148:151)' A = 147000 148000 149000 150000
Now let s get the corresponding temperatures:
>> B = y(148:151)' B = 785228 770074 754535 738604
MATLAB Demysti ed
We can arrange the data into a two column table, with the left column containing the times and the right column the temperatures:
>> Table = [A B] Table = 147000 148000 149000 150000 785228 770074 754535 738604
So for instance, we see that at 149 hours the block is estimated to be at about 75 degrees Now let s generate a plot of the data from 10 hours to 15 hours First we find the array index for the time at 10 hours We had generated the time in increments of 01, so we can find it by searching for t > 99:
>> find(t >99) ans = Columns 1 through 18 101 111 112 102 113 103 114 104 115 105 116 106 117 107 118 108 109 110
Columns 19 through 36 119 129 130 120 131 121 132 122 133 123 134 124 135 125 136 126 127 128
Columns 37 through 51 137 147 148 138 149 139 150 140 151 141 142 143 144 145 146
CHAPTER 10 Curve Fitting
120 Temp(F) 100 80 60 10
125 13 Time(h)
Figure 10-7 A plot of estimated temperatures in a time range well beyond that where the data was collected
Next we create a new array containing these time values:
>> T1 = t(101:151);
Now let s grab the temperatures over that range and store them:
>> TEMP2 = y(101:151);
Then we can plot them:
>> plot(T1,TEMP2),xlabel('time(h)'),ylabel('Temp(F)'), axis([10 15 60 120])
The result is shown in Figure 10-7 The model predicts that over this 5 hour range the temperature of the metal block will drop more than 40 degrees
Fitting to an Exponential Function
Other types of fits besides fitting to a polynomial are possible, we briefly mention one In some cases it may be necessary to fit the data to an exponential function The fit in this case is: y = b(10)mx where x is the independent variable and y is the dependent variable Now we define the relations: w = log10 y z=x and then fit the data to a line of the form: w = p1z + p2
Copyright © OnBarcode.com . All rights reserved.