{"id":166,"date":"2010-06-21T20:38:19","date_gmt":"2010-06-22T01:38:19","guid":{"rendered":"http:\/\/blogs.cae.tntech.edu\/mwr\/?p=166"},"modified":"2024-10-27T14:26:19","modified_gmt":"2024-10-27T14:26:19","slug":"power-law-curve-fits-in-matlab","status":"publish","type":"post","link":"https:\/\/sites.tntech.edu\/renfro\/2010\/06\/21\/power-law-curve-fits-in-matlab\/","title":{"rendered":"Power Law Curve Fits in MATLAB"},"content":{"rendered":"<p>(<a href=\"http:\/\/en.wikipedia.org\/wiki\/Power_law\">See this Wikipedia article for a quick review of Power law fits<\/a>.)<\/p>\n<p>So linear curve fits are easy in MATLAB &#8212; just use p=polyfit(x,y,1), and p(1) will be the slope and p(2) will be the intercept. Power law fits are nearly as easy. Recall that any data conforming to a linear fit will fall along a given by the equation [latex]y=kx+a[\/latex]<br \/>\nSimilarly, any data conforming to a power law fit will fall along a curve given by the equation [latex]y=ax^k[\/latex]<br \/>\nIf we plot the second equation on log-log axes, it describes a family of straight lines. Put another way, if we take the log of y and x and plot them on linear axes, those logs will fall along a straight line. So all we need to do in MATLAB is to take the log of both x and y, and then let polyfit do its job. For example:<\/p>\n<pre>clear all\nclose all\nx=[0.4 0.5 0.6 0.7];\ny=[1.429 1 0.778 0.5675];\nlogx=log(x);\nlogy=log(y);\np=polyfit(logx,logy,1);\nplot(logx,logy,'bo');\naxis equal square\ngrid\nxlabel('log(x)');\nylabel('log(y)');\nk=p(1);\nloga=p(2);\na=exp(loga);\nhold on; plot(logx,k*logx+loga,'g')\nlegend('Data',sprintf('y=%.3f{}log(x)+log(%.3f)',k,a));\nfigure\nplot(x,y,'bo');\nxlabel('x');\nylabel('y');\naxis equal square\ngrid\nhold on; plot(x,a*x.^k,'g')\nlegend('Data',sprintf('y=%.3f{}x^{%.3f}',a,k));<\/pre>\n<p>returns the following figures:<\/p>\n<p><a href=\"http:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-168\" src=\"http:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig1-1024x768.png\" alt=\"fig1\" width=\"1024\" height=\"768\" srcset=\"https:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig1-1024x768.png 1024w, https:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig1-300x225.png 300w, https:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig1-768x576.png 768w, https:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig1.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><a href=\"http:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-167\" src=\"http:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig2-1024x768.png\" alt=\"fig2\" width=\"1024\" height=\"768\" srcset=\"https:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig2-1024x768.png 1024w, https:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig2-300x225.png 300w, https:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig2-768x576.png 768w, https:\/\/sites.tntech.edu\/renfro\/wp-content\/uploads\/sites\/111\/2010\/06\/fig2.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>(See this Wikipedia article for a quick review of Power law fits.) So linear curve fits are easy in MATLAB &#8212; just use p=polyfit(x,y,1), and p(1) will be the slope and p(2) will be the intercept. Power law fits are nearly as easy. Recall that any data conforming to a linear fit will fall along &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sites.tntech.edu\/renfro\/2010\/06\/21\/power-law-curve-fits-in-matlab\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Power Law Curve Fits in MATLAB&#8221;<\/span><\/a><\/p>\n","protected":false},"author":87,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-166","post","type-post","status-publish","format-standard","hentry","category-matlab","entry"],"_links":{"self":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/comments?post=166"}],"version-history":[{"count":1,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/166\/revisions"}],"predecessor-version":[{"id":447,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/166\/revisions\/447"}],"wp:attachment":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/media?parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/categories?post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/tags?post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}