{"id":2937,"date":"2011-10-28T12:59:10","date_gmt":"2011-10-28T12:59:10","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/28\/numerical-methods-on-piecewise-continuous-functions\/"},"modified":"2011-10-28T12:59:10","modified_gmt":"2011-10-28T12:59:10","slug":"numerical-methods-on-piecewise-continuous-functions","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/28\/numerical-methods-on-piecewise-continuous-functions\/","title":{"rendered":"Numerical methods on piecewise-continuous functions"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/23972-chebfun-v4-old-version--please-download-current-version-instead\">Chebfun v2<\/a> by the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/55471\">Chebfun Team<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Thorough Documentation<\/a><\/li>\r\n         <li><a href=\"#2\">Chebfun Function<\/a><\/li>\r\n         <li><a href=\"#8\">Comments<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Thorough Documentation<a name=\"1\"><\/a><\/h3>\r\n   <p>I was initially drawn to this entry because of the comprehensive documentation that was included with it. You can directly\r\n      view it from the File Exchange page:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_chebfun\/chebfun_guides.png\"> <\/p>\r\n   <p>Their user's guide is extremely detailed and helpful. I had very little prior knowledge of the concepts covered by this tool,\r\n      but after reading through it, I've come to appreciate the usefulness and the power of the tool. They created the guide using\r\n      MATLAB's <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/matlab_env\/f6-22451.html\">publishing<\/a> functionality, which is an extremely effective way of providing documentation and examples for the end-users, because of\r\n      the ability to intermix code, figures, explanatory text, and equations. Find more information about publish from this <a href=\"https:\/\/www.mathworks.com\/academia\/matlab-examples.html\">page<\/a> on our Academic website.\r\n   <\/p>\r\n   <h3>Chebfun Function<a name=\"2\"><\/a><\/h3>\r\n   <p>Now, let's take a look at the tool.<\/p>\r\n   <p>Borrowing the words from their documentation, a <tt>chebfun<\/tt> is a function of one variable defined within a particular interval. It allows you to perform symbolic-like operations with\r\n      the performance of numerics. The underlying implementation of <tt>chebfun<\/tt> is based on the mathematical fact that smooth functions can be represented very efficiently by expansions in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Chebyshev_polynomials\">Chebyshev polynomials<\/a>, similar to how Fourier series work with smooth periodic functions. By decomposing a function into these polynomial interpolants,\r\n      many mathematical operations can be carried out efficiently.\r\n   <\/p>\r\n   <p>Let's define a <tt>chebfun<\/tt> for <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_chebfun\/potw_chebfun_eq29969.png\">  within the interval [0 2].\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">f = chebfun(@(x) sin(x)+cos(3.3*x)-0.5*x.^2, [0 2])<\/pre><pre style=\"font-style:oblique\">f = \r\n   chebfun column (1 smooth piece)\r\n          interval          length   values at Chebyshev points\r\n(        0,        2)        21            1          1          1 ...      -0.14\r\n \r\n<\/pre><p>You can see that this function is represented by 21 points, i.e. a polynomial of degree 20. Let's plot it, along with the\r\n      intermediate points (Chebyshev points)\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">plot(f, <span style=\"color: #A020F0\">'.-'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_chebfun\/potw_chebfun_01.png\"> <p>This <tt>chebfun<\/tt> representation can be evaluated at arbitrary points:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">f([0.2, 0.5, 0.9, 1.5, 1.85])<\/pre><pre style=\"font-style:oblique\">ans =\r\n    0.9687    0.2753   -0.6070    0.1079    0.2342\r\n<\/pre><p>To calculate the integral from 0 to 2,<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">sum(f)<\/pre><pre style=\"font-style:oblique\">ans =\r\n    0.1772\r\n<\/pre><p>The roots can be found by<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">r = roots(f)\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\nplot(r, f(r), <span style=\"color: #A020F0\">'ro'<\/span>, <span style=\"color: #A020F0\">'MarkerFaceColor'<\/span>, <span style=\"color: #A020F0\">'r'<\/span>);<\/pre><pre style=\"font-style:oblique\">r =\r\n    0.5953\r\n    1.4429\r\n    1.9557\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_chebfun\/potw_chebfun_02.png\"> <p>By now, you probably have noticed that <tt>chebfun<\/tt> is implemented using <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/matlab_oop\/ug_intropage.html\">object-oriented programming<\/a>, with a number of overloaded methods, such as <tt>plot<\/tt>, <tt>sum<\/tt>, and <tt>roots<\/tt>.\r\n   <\/p>\r\n   <p>I can say for sure that I'm not doing justice to this entry with this short blog post. I've just scratched the surface with\r\n      what could be done with this tool. I highly encourage you to take a look through the documentation and give it a try. On the\r\n      download page, it says that they have Version 4 available for download off of their university website. I'm hoping that they\r\n      will also update the version on the File Exchange.\r\n   <\/p>\r\n   <h3>Comments<a name=\"8\"><\/a><\/h3>\r\n   <p>Let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2937#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/23972-chebfun-v4-old-version--please-download-current-version-instead#comments\">comment<\/a> for the Chebfun Team.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_4022bd5b3e7447c0af5c304aba87029e() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='4022bd5b3e7447c0af5c304aba87029e ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 4022bd5b3e7447c0af5c304aba87029e';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Jiro Doke';\r\n        copyright = 'Copyright 2011 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_4022bd5b3e7447c0af5c304aba87029e()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.13<br><\/p>\r\n<\/div>\r\n<!--\r\n4022bd5b3e7447c0af5c304aba87029e ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/23972-chebfun-v4-old-version--please-download-current-version-instead Chebfun v2> by\r\n% the <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/55471\r\n% Chebfun Team>.\r\n\r\n%% Thorough Documentation\r\n%\r\n% I was initially drawn to this entry because of the comprehensive\r\n% documentation that was included with it. You can directly view it from\r\n% the File Exchange page:\r\n%\r\n% <<chebfun_guides.png>>\r\n%\r\n% Their user's guide is extremely detailed and helpful. I had very little\r\n% prior knowledge of the concepts covered by this tool, but after reading\r\n% through it, I've come to appreciate the usefulness and the power of the\r\n% tool. They created the guide using MATLAB's\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/matlab_env\/f6-22451.html\r\n% publishing> functionality, which is an extremely effective way of\r\n% providing documentation and examples for the end-users, because of the\r\n% ability to intermix code, figures, explanatory text, and equations. Find\r\n% more information about publish from this\r\n% <https:\/\/www.mathworks.com\/academia\/matlab-examples.html page> on our Academic\r\n% website.\r\n\r\n%% Chebfun Function\r\n% Now, let's take a look at the tool. \r\n%\r\n% Borrowing the words from their documentation, a |chebfun| is a function\r\n% of one variable defined within a particular interval. It allows you to\r\n% perform symbolic-like operations with the performance of numerics. The\r\n% underlying implementation of |chebfun| is based on the mathematical fact\r\n% that smooth functions can be represented very efficiently by expansions\r\n% in <http:\/\/en.wikipedia.org\/wiki\/Chebyshev_polynomials Chebyshev\r\n% polynomials>, similar to how Fourier series work with smooth periodic\r\n% functions. By decomposing a function into these polynomial interpolants,\r\n% many mathematical operations can be carried out efficiently.\r\n%\r\n% Let's define a |chebfun| for $sin(x)+cos(3.3x)-0.5x^2$ within the\r\n% interval [0 2].\r\n% \r\n\r\nf = chebfun(@(x) sin(x)+cos(3.3*x)-0.5*x.^2, [0 2])\r\n\r\n%%\r\n% You can see that this function is represented by 21 points, i.e. a\r\n% polynomial of degree 20. Let's plot it, along with the intermediate\r\n% points (Chebyshev points)\r\n\r\nplot(f, '.-')\r\n\r\n%%\r\n% This |chebfun| representation can be evaluated at arbitrary points:\r\n\r\nf([0.2, 0.5, 0.9, 1.5, 1.85])\r\n\r\n%%\r\n% To calculate the integral from 0 to 2,\r\n\r\nsum(f)\r\n\r\n%%\r\n% The roots can be found by\r\n\r\nr = roots(f)\r\nhold on\r\nplot(r, f(r), 'ro', 'MarkerFaceColor', 'r');\r\n\r\n%%\r\n% By now, you probably have noticed that |chebfun| is implemented using\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/matlab_oop\/ug_intropage.html\r\n% object-oriented programming>, with a number of overloaded methods, such\r\n% as |plot|, |sum|, and |roots|.\r\n%\r\n% I can say for sure that I'm not doing justice to this entry with this\r\n% short blog post. I've just scratched the surface with what could be done\r\n% with this tool. I highly encourage you to take a look through the\r\n% documentation and give it a try. On the download page, it says that they\r\n% have Version 4 available for download off of their university website.\r\n% I'm hoping that they will also update the version on the File Exchange.\r\n\r\n%% Comments\r\n%\r\n% Let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2937#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/23972-chebfun-v4-old-version--please-download-current-version-instead#comments\r\n% comment> for the Chebfun Team.\r\n\r\n##### SOURCE END ##### 4022bd5b3e7447c0af5c304aba87029e\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Jiro's pick this week is Chebfun v2 by the Chebfun Team.\r\n      \r\n   \r\n   Contents\r\n   \r\n      \r\n        ... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/28\/numerical-methods-on-piecewise-continuous-functions\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2937"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2937"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2937\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}