{"id":1042,"date":"2017-09-12T02:23:33","date_gmt":"2017-09-11T18:23:33","guid":{"rendered":"http:\/\/people.utm.my\/yap\/?page_id=1042"},"modified":"2017-09-21T17:45:34","modified_gmt":"2017-09-21T09:45:34","slug":"linear-fitting-with-hookes-law","status":"publish","type":"page","link":"https:\/\/people.utm.my\/yap\/linear-fitting-with-hookes-law\/","title":{"rendered":"Linear fitting with\u00a0Hooke&#8217;s Law"},"content":{"rendered":"<p style=\"text-align: right;\"><a href=\"https:\/\/people.utm.my\/yap\/plotting-and-fitting-using-gnuplot\/\">(Back to index)<\/a><\/p>\n<p><span style=\"font-size: 12pt;\">Assuming that this is the data for a linear experiment with ideally, zero y-intercept:<\/span><\/p>\n<h3>Data<\/h3>\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/0B8auPlQqHQ6hOWhzOGlLYUtWRTQ\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\"><span style=\"font-size: 12pt;\">Click here to download the data<\/span><\/a><span style=\"font-size: 12pt;\">\u00a0or copy the following data into a notepad and save it as a text file.\u00a0<\/span><span style=\"font-size: 12pt;\">I normally prefer to change the filetype from &#8220;.txt&#8221; to &#8220;.dat&#8221;, simply because, it contains data.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-size: 12pt;\"># m (g)<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">Data 1<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">Data 2<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">Data 3<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">average<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">std.dev<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">200<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">5.683631<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">6.29861<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">8.381023<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">6.787755<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">1.413658<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">400<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">10.23901<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">13.5709<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">15.18523<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">12.99838<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">2.522326<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">600<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">11.84209<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">11.36025<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">9.422947<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">10.8751<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">1.280467<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">800<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">16.33589<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">16.92676<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">19.82742<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">17.69669<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">1.868766<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">1000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">22.32341<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">23.72259<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">20.2721<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">22.10603<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">1.735483<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">1200<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">24.86626<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">27.70103<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">28.07837<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">26.88189<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">1.755747<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">1400<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">28.19161<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">29.78272<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">31.26129<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">29.74521<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">1.535185<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">1600<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">34.77228<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">34.02847<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">30.23366<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">33.01147<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">2.434233<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">1800<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">37.84083<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">38.05711<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">36.07914<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">37.32569<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">1.084949<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">2000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">37.64023<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">38.79702<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">42.7417<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">39.72632<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">2.674686<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: 12pt;\">In this data, the first column is the mass (in grams), hung under a spring.<\/span><br \/>\n<span style=\"font-size: 12pt;\"> The spring extends and the elongation is recorded.<\/span><br \/>\n<span style=\"font-size: 12pt;\"> The experiment is repeated three times to produce three sets of data.<\/span><br \/>\n<span style=\"font-size: 12pt;\"> The average and standard deviation was calculated for these data.<\/span><\/p>\n<h3>Tasks:<\/h3>\n<p><span style=\"font-size: 12pt;\">For this data, we would use the linear equation\u00a0y = mx + c.<\/span><br \/>\n<span style=\"font-size: 12pt;\"> You would need to produce 5 fits and plots to compare the results.<\/span><br \/>\n<span style=\"font-size: 12pt;\"> These are the tasks:<\/span><\/p>\n<ol>\n<li><span style=\"font-size: 12pt;\">Fit and plot for Data #1 (not the average), where the parameters m and c are fitted (adjusted) to the graph.<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Fit and plot for Data #1 (not the average), where only parameter m is fitted and parameter c is fixed to zero.<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Fit and plot for Average Data, where the parameters m and c are fitted (adjusted) to the graph, without\u00a0standard deviation data.<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Fit and plot for Average Data, where the parameters m and c are fitted (adjusted) to the graph, with\u00a0standard deviation data.<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Fit and plot for Average Data, where only parameter m is fitted and parameter c is fixed\u00a0to zero\u00a0with standard deviation data.<\/span><\/li>\n<\/ol>\n<h3>Required Knowledge<\/h3>\n<p><span style=\"font-size: 12pt;\">To perform the tasks about, one would require the <a href=\"https:\/\/people.utm.my\/yap\/importing-data-into-gnuplot\/\">basic knowledge<\/a> of importing data into gnuplot.<\/span><\/p>\n<h3>Code &#8211; Task 1<\/h3>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">y1(x) = m1*x + c1<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">m1 = 2<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">c1 = 0.1<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">fit y1(x) &#8216;data.dat&#8217; using 2:5 via m1,c1<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">plot &#8216;data.dat&#8217; using 2:5 with points<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">replot y1(x) with line t &#8220;y1(x) : Single Data with y-intercept&#8221;<\/span><\/p>\n<p><strong>Explanation<\/strong><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">y1(x) = m1*x + c1<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">First, we would need to define the fitting equation. \u00a0In this case, the fitting equation is a simple linear equation with two variables, <span style=\"font-family: 'courier new', courier, monospace;\">m1<\/span> and <span style=\"font-family: 'courier new', courier, monospace;\">c1<\/span>.<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">m1 = 2<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\"> c1 = 0.1<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">Then we assign a starting value for m1 and c1. Do not write zero. \u00a0Try to write something within the same order of the actual value. \u00a0The only way to know the actual value to to try to plot the graph <strong>without fitting.<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">fit y1(x) &#8216;data.dat&#8217; using 2:5 via m1,c1<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">Next, this command fits the <span style=\"font-family: 'courier new', courier, monospace;\">y1(x)<\/span> equation with the data &#8216;<span style=\"font-family: 'courier new', courier, monospace;\">data.dat<\/span>&#8216;. \u00a0The command &#8220;<span style=\"font-family: 'courier new', courier, monospace;\">using 2:5<\/span>&#8221; selects only columns 2 and 5 for data-fitting. \u00a0The values which are adjusted are written using &#8220;<span style=\"font-family: 'courier new', courier, monospace;\">via m1,c1<\/span>&#8221; where m1 and c1 will be changed to get the best fit.<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">plot &#8216;data.dat&#8217; using 2:5 with points<\/span><\/p>\n<p>This command plots the original data with data points<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">replot y1(x) with line title &#8220;y1(x) : Single Data with y-intercept&#8221;<\/span><\/p>\n<p>This command plots the y1(x) equation that has been fitted with a title.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: right;\"><a href=\"https:\/\/people.utm.my\/yap\/plotting-and-fitting-using-gnuplot\/\">(Back to index)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Back to index) Assuming that this is the data for a linear experiment with ideally, zero y-intercept: Data Click here to download the data\u00a0or copy the following data into a notepad and save it as a text file.\u00a0I normally prefer to change the filetype from &#8220;.txt&#8221; to &#8220;.dat&#8221;, simply because, it contains data. # m [&hellip;]<\/p>\n","protected":false},"author":14205,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"class_list":["post-1042","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/pages\/1042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/users\/14205"}],"replies":[{"embeddable":true,"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/comments?post=1042"}],"version-history":[{"count":0,"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/pages\/1042\/revisions"}],"wp:attachment":[{"href":"https:\/\/people.utm.my\/yap\/wp-json\/wp\/v2\/media?parent=1042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}