<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Matlab</title>
        <link>http://blogs.ugidotnet.org/Andrew/category/Matlab.aspx</link>
        <description>Matlab</description>
        <language>it-IT</language>
        <copyright>Andrea Sansottera</copyright>
        <generator>Subtext Version 2.6.0.0</generator>
        <item>
            <title>[OT: Matlab] Calcolo e la rappresentazione di una serie di Fourier</title>
            <link>http://blogs.ugidotnet.org/Andrew/archive/2005/07/06/22280.aspx</link>
            <description>&lt;P&gt;&lt;A title="" href="http://en.wikipedia.org/wiki/Matlab" target="" name=""&gt;Matlab&lt;/A&gt; &amp;#232; un ambiente destinato al calcolo numerico, alla simulazione e allo sviluppo di modelli matematici. Il linugaggio Matlab &amp;#232; dinamico; i tipi base non sono valori scalari, bens&amp;#236; matrici. Il codice &amp;#232; JIT-compilato, la memoria &amp;#232; gestita da un garbage collector.&lt;/P&gt;
&lt;P&gt;Durante la preparazione dell'esame di Analisi 2 - presso il &lt;A title="" href="http://www.polimi.it/" target="" name=""&gt;Politecnico di Milano&lt;/A&gt; - ho sviluppato questa semplice routine per il calcolo e la rappresentazione della serie di &lt;A title="" href="http://en.wikipedia.org/wiki/Jean_Baptiste_Joseph_Fourier" target="" name=""&gt;Fourier&lt;/A&gt; associata ad una funzione. La pubblico con la speranza che possa essere utile ad altri studenti e interessare chi non ha mai utilizzato l'ambiente Matlab.&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;%&lt;BR&gt;%   DRAWFOURIER&lt;BR&gt;%&lt;BR&gt;% Definition:&lt;BR&gt;%   function [xvalues, yvalues] = drawfourier(y, x, from, to, step, precision)&lt;BR&gt;%&lt;BR&gt;% Description:&lt;BR&gt;%   Draws the graphic of the function y(x) and the graphic of its Fourier's&lt;BR&gt;%   series. Requires the Symbolic Math Toolbox.&lt;BR&gt;% &lt;BR&gt;% Arguments:&lt;BR&gt;%   y:              symbolic expression of the function&lt;BR&gt;%   x:              symbolic variable rappresenting the independent variable&lt;BR&gt;%   from:           left boundary of the period&lt;BR&gt;%   to:             right boundary of the period&lt;BR&gt;%   step:           the distance beetween two points in which the series is computed&lt;BR&gt;%   precison:       the maximum index of the series&lt;BR&gt;% &lt;BR&gt;% Returned values:&lt;BR&gt;%   xvalues:        the values in the domain of the Fourier's series&lt;BR&gt;%   yvalues:        the values of the Fourier's series&lt;BR&gt;%&lt;BR&gt;% Example:&lt;BR&gt;%   x = sym('x'); drawfourier(x^2, x, -pi, pi, 0.1, 50);&lt;BR&gt;%&lt;BR&gt;% Information:&lt;BR&gt;%   Author:         Andrea Sansottera (andrea.sansottera@fastwebnet.it)&lt;BR&gt;%   Date:           June 20th 2005&lt;BR&gt;%   Version:        0.6&lt;BR&gt;%   License:        GPL&lt;BR&gt;&lt;BR&gt;function [xvalues, yvalues] = drawfourier(y, x, from, to, step, precision)&lt;BR&gt;&lt;BR&gt;% starts the stopwatch&lt;BR&gt;tic;&lt;BR&gt;&lt;BR&gt;% initializes the symbolic index of the series&lt;BR&gt;k = sym('k');&lt;BR&gt;&lt;BR&gt;% initializes period and pulsation&lt;BR&gt;t = (to - from);&lt;BR&gt;c = 2/t;&lt;BR&gt;omega = (2*pi)/t;&lt;BR&gt;&lt;BR&gt;% computes the Fourier coefficients of the series&lt;BR&gt;a0 = c * int (y, from, to);&lt;BR&gt;ycos = y * cos(omega*k*x);&lt;BR&gt;ak = c * int(ycos, from, to);&lt;BR&gt;ysin = y * sin(omega*k*x);&lt;BR&gt;bk = c * int(ysin, from, to);&lt;BR&gt;&lt;BR&gt;% defines the domain of the series&lt;BR&gt;xvalues = [from : step : to];&lt;BR&gt;&lt;BR&gt;% foreach point in the domain of the function&lt;BR&gt;for i = [1 : length(xvalues)]&lt;BR&gt;    % computes the value of the Fourier's series&lt;BR&gt;    yvalues(i) = subs(a0/2);&lt;BR&gt;    for kval = 1 : precision&lt;BR&gt;        yvalues(i) = yvalues(i) + subs(ak*cos(omega*k*x), {k, x}, {kval, xvalues(i)});&lt;BR&gt;        yvalues(i) = yvalues(i) + subs(bk*sin(omega*k*x), {k, x}, {kval, xvalues(i)});&lt;BR&gt;    end&lt;BR&gt;end&lt;BR&gt;&lt;BR&gt;% plots the function&lt;BR&gt;ezplot(y, [from, to]);&lt;BR&gt;% keeps the graphic on the figure&lt;BR&gt;hold on;&lt;BR&gt;% plots the Fourier's series&lt;BR&gt;plot(xvalues, yvalues, 'r');&lt;BR&gt;% sets the labels of the figure&lt;BR&gt;xlabel('x');&lt;BR&gt;ylabel('y');&lt;BR&gt;% sets the title of the figure&lt;BR&gt;figure_title = sprintf('%s  period = [%.2f, %.2f]   step = %.2f   k = [1, %d]', char(y), from, to, step, precision);&lt;BR&gt;title(figure_title);&lt;BR&gt;% displays a legend&lt;BR&gt;series_label = sprintf('Fourier''s series of %s', [char(y)]);&lt;BR&gt;legend(char(y), series_label);&lt;BR&gt;% setups axis&lt;BR&gt;axis([from to min(yvalues) max(yvalues)]);&lt;BR&gt;&lt;BR&gt;% stops the stopwatch and displays the elapsed time&lt;BR&gt;toc;&lt;BR&gt;&lt;BR&gt;end&lt;BR&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;P&gt;Ecco un esempio. Disegniamo la parabola di equazione x^2 e la sua serie di Fourier, nell'intervallo [0, 2*pi], valutandola ogni 0.05. Consideriamo solamente i primi 5 termini della serie.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;syms x; drawfourier (x^2, x, 0, 2*pi, 0.05, 5)&lt;/EM&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;IMG alt="" hspace=0 src="http://digilander.libero.it/all_apologies/blog/images/x^2_01.jpg" align=baseline border=0&gt;&lt;/P&gt;
&lt;P&gt;Essendo la funzione limitata e monotona a tratti, sono soddisfatte le ipotesi del teorema di convergenza puntuale. Cerchiamo di sfruttarlo per ottenere una migliore approssimazione. Scegliamo un intervallo in cui la funzione presenti simmetria pari: in tale intervallo soddisfer&amp;#224; la condizione di raccordo. Poich&amp;#232; la funzione &amp;#232; continua la serie di Fourier converge in ogni singolo punto alla y(x). Si noti come in questo modo l'approssimazione migliori, pur sottoponendo la macchina allo stesso carico computazionale (il termini valutati sono sempre i primi 5).&lt;/P&gt;
&lt;P align=left&gt;&lt;EM&gt;syms x; drawfourier (x^2, x, -pi, +pi, 0.05, 5)&lt;/EM&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;IMG alt="" hspace=0 src="http://digilander.libero.it/all_apologies/blog/images/x^2_02.jpg" align=baseline border=0&gt;&lt;/P&gt;
&lt;P&gt;Com'&amp;#232; facilmente intuibile, aumentando il numero di termini della serie valutati, la precisione migliora ulteriormente. &lt;/P&gt;&lt;EM&gt;syms x; drawfourier (x^2, x, 0, 2*pi, 0.05, 20)&lt;/EM&gt; 
&lt;P align=left&gt;&lt;IMG alt="" hspace=0 src="http://digilander.libero.it/all_apologies/blog/images/x^2_03.jpg" align=baseline border=0&gt;&lt;/P&gt;
&lt;P align=left&gt; &lt;/P&gt;&lt;/SPAN&gt;&lt;!-- Powered by IMHO Instant Blogger Copyright (c) 2004 A.Boschin - http://www.elite.boschin.it --&gt;&lt;img src="http://blogs.ugidotnet.org/Andrew/aggbug/22280.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Andrea Sansottera</dc:creator>
            <guid>http://blogs.ugidotnet.org/Andrew/archive/2005/07/06/22280.aspx</guid>
            <pubDate>Wed, 06 Jul 2005 13:11:00 GMT</pubDate>
            <comments>http://blogs.ugidotnet.org/Andrew/archive/2005/07/06/22280.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://blogs.ugidotnet.org/Andrew/comments/commentRss/22280.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>