Premium Essay

Matlab Ode

In:

Submitted By 8796li
Words 983
Pages 4
MATLAB 數值微積分與微分方程式求解

數值積分

b a

f ( x) dx 等於由界限範圍 x = a 到 x = b 之間

曲線 f(x) 底下的面積

(a) 矩形以及 (b) 梯形 數值積分的圖解說明

數值積分
已知數據點的積分, 已知數據點的積分,不知函數 f(x):trapz : I = trapz(x, y)
(梯形積分法 梯形積分法) 梯形積分法

x : 數據點之 x 值所構成的向量 y : 數據點之 f(x) 值所構成的向量

Ex:
>>x=[0 10 20 30 40]; >>y=[0.5 0.7 0.9 0.6 0.4]; >>area=trapz(x,y) %梯形法 梯形法 area = 26.5000

數值積分
之形式: 已知函數 f(x) 之形式:quad , quadl I = quad(@fun, a, b) I = quadl(@fun, a, b)
(適應性辛普森法)

(羅伯特二次式)

fun:定義函數的 function m-file 檔名 a :積分下限 b :積分上限

數值積分
Ex:



1

0

e − x cos( x) dx

1. edit fun.m function y=fun(x) y=exp(-x).*cos(x); 2. 求積分 回到Matlab Command Window) 求積分(回到 area=quadl(@fun,0,1) 亦可使用 area=quadl(‘exp(-x).*cos(x)’,0,1) NOTE: 函數內之數學運算必須使用向量個別元素之運算 (.* ./ .^) (註:比較此結果與利用trapz指令計算之結果)

數值微分
已知數據點的微分

在 x2 之微分

數值微分
可利用 diff 函數

Ex:
>>x=0:0.1:1; >>y=[0.5 0.6 0.7 0.9 1.2 1.4 1.7 2.0 2.4 2.9 3.5]; >>dx=diff(x); >>dy=diff(y); >>dydx=diff(y)./diff(x)

數值微分
Ex: f ( x) = sin( x), f ′( x) = ? x ∈ [ 0, π ]
>> >> >> >> >> >> >> x = linspace(0,pi,20); y = sin(x); d = diff(y)./diff(x); % backward or forward difference dc = (y(3:end)-y(1:end-2))./(x(3:end)-x(1:end-2)); % central difference dy = cos(x); % 實際微分值 plot(x, dy, x(2:end), d,'o', x(1:end-1), d,'x', x(2:end-1), dc,'^') xlabel('x'); ylabel('Derivative')
1 0.8 0.6 0.4 Derivative 0.2 0 -0.2 -0.4 -0.6 -0.8 -1

0

0.5

1

1.5 x

2

2.5

3

3.5

工程問題中常微分方程式的解

常微分方程式
常微分方程式之形式: dy = f (t, y) dt 一般解之形式:

yi +1 = yi + φ h φ 是斜率 增量函數 (increment function),被用來自舊值yi 斜率或增量函數 斜率
外插到新值yi+1,h為步長大小 (step size)。 步長大小 此方法稱為單步方法 (one-step method),因為增量函數的 單步方法 值是根據單一點 i 的資訊。

歐拉法
在ti處的一次微分形式提供了直接的斜率估計:
dy = f (t i , yi ) dt ti

φ = f ( ti , yi ) yi +1 = yi + f ( ti , yi ) h

此公式即稱為歐拉法 歐拉法 (Euler's method) 。新的值y 利用斜率(等於在t處的一 階微分)在步長大小h上做 線性外插來得到預測值。

倫基-庫達法
倫基-庫達 倫基-庫達(RK)法(Runge-Kutta methods)可以達到泰勒級數 法

Similar Documents

Free Essay

Matlab and Ode Solvers

...Lab 0: MATLAB and ODE Solvers | ME 4173 Robot Kinematics | | | | Introduction The following report will display the results and conclusions of an experiment to simulate the output of an inverse pendulum system in MATLAB. The objectives of this experiment were to review MATLAB programming and using MATLAB to simulate ODEs and systems. Objectives * Examine the basics of MATLAB * Use MATLAB to simulate a system * Use ODE solvers to numerically integrate the system over a set time period Apparatus The apparatus used in this experiment was MATLAB. It was used to provide a simulation environment to analyze the inverse pendulum’s motion. Experiments and Results There were six components of this experiment. This experiment was mostly familiarizing with MATLAB. All code used is illustrated in the Appendix – Code. The first part consisted of learning commands within the MATLAB environment. It was a brief overview of how commands work in MATLAB. There was no code used in the part of the experiment. The second part of the experiment examined how arrays were created and used in MATLAB. The first step was to create a matrix. This matrix was then subjected to various commands including eye( ), zeroes( ), and ones( ). Indexing was also used to access various parts of the matrix. Matrix operations such as transpose, inverse, size and length were also shown. Part three of the experiment explained how a script was created and what it was...

Words: 828 - Pages: 4

Free Essay

Forecasting Models

...MATLAB® Getting Started Guide R2011b How to Contact MathWorks Web Newsgroup www.mathworks.com/contact_TS.html Technical Support www.mathworks.com comp.soft-sys.matlab suggest@mathworks.com bugs@mathworks.com doc@mathworks.com service@mathworks.com info@mathworks.com Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information 508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 For contact information about worldwide offices, see the MathWorks Web site. MATLAB® Getting Started Guide © COPYRIGHT 1984–2011 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights...

Words: 36443 - Pages: 146

Free Essay

Human Step Detection and Counting with a Microphone (June 2015)

...alternative use of sensors for detecting human movements such as footsteps and that is done for various reasons such as security or just for lightning a lamp automatically. We developed a Simulink model in Matlab to simulate a system that analyses the footsteps of three 25 years old men. Those men had different heights and weights. The data were recorded and analyzed using filtering and conditioning blocks of Matlab. The System collected 3 sets of steps. The first set had 5 steps with 5 detections. The second set had 8 steps with 3 detection and the third set had 4 steps with 1 detections. In total, there were 17 steps where 9 steps were detected. I. C. Procedure During the first part of the experiment, the footsteps were recorded on the main corridor of the first floor of the house 21, located in the University of Kristianstad. We also recorded the steps at our respective houses. The experiment was carried on a floor without carpet to allow a better collection of the data. This procedure was repeated several times, until satisfactory data without much noisy could be acquired. INTRODUCTION T HE objective of this work was to detect the steps of a person using a microphone array embedded in our computer together with the Simulink library of Matlab. We have some background of the idea after reading a few articles regarding this type of experiments. Fig. 1. Simulink models used to record the steps In the articles we read, the experiment...

Words: 1833 - Pages: 8

Free Essay

Ode to Autumn

...junior high school. Lines 3-4 Conspiring with him how to load and bless With fruit the vines that round the thatch-eves run; * Ah, so now the sun and autumn are "conspiring," eh? Looks like we might have to separate the two of them. What are they whispering about over there? * OK, so not quite as thrilling as we thought. They are planning how to make fruit grow on the vines that curl around the roofs ("eves") of thatched cottages. * The image highlights the weight of the fruit as it "loads" down the vines. * Thatched cottages suggest a pastoral setting, characterized by shepherds, sheep, maidens, and agriculture. The "pastoral" as a literary genre was thought to originate in Ancient Greece, and the ode is a Greek form, so it is appropriate for this ode to include...

Words: 3356 - Pages: 14

Free Essay

Philosophy

...Name: Lecturer: Course: Date: According to Nietzsche's theory ,it appears to be sensible to say that delight and torment, bliss and enduring, are related to the point that they are in some sense "twins," or if nothing else not finish contrary energies, in the accompanying ways. In the first place, there are a few situations where joy results from torment as blocks succeed: the more noteworthy the obstacle, the more prominent the inclination of force and in this way to joy (Robinson,15) Second, while agony may offer ascent to pleasure in some cases, it doesn't appear that the inverse holds, i.e., joy overcome does not give rise to torment. Third, and this does not so much talk against their being contrary energies, pain and joy has an equal relationship in which the experience of the one hues our experience of the other. This shading of experience could go in any case: the significance of misery may either build or decline our inclination of joy, and the other way around. At any rate to some degree; it appears we could say the harsher the conditions succeed; the more one gets to be more grounded and glad. In the Nietzsche's hypothesis, while talking about our propensity to misrepresent our agony also, enduring, Nietzsche composes, A misfortune is a misfortune for scarcely on hour; some way or another it likewise presents to us some blessing from paradise new quality, for instance, or if nothing else another open door for class So, it is clear that Nietzsche does not feel...

Words: 720 - Pages: 3

Free Essay

Critical Essay - Ode on a Grecian Urn

...Ode on a Grecian Urn John Keats’s poem “Ode on a Grecian Urn” is about the images that are on the urn. The narrator comments on each of the several scenes that are illustrated on the urn. He says that the painting is silent and does not change. What is painted on the urn is there forever. In its never-changing aspect, all the people stay fair and young, untouched by time. However, they cannot fulfill what they want to in life. Although people get old, the urn itself will remain. The urn teaches us that all we can do in life is to appreciate beauty and to be aware. The narrator’s idea of living in the eternal world of the illustrations on the urn changes from excitement at the beginning of the poem to nervousness at the end. At first, the narrator is fascinated by never-changing nature of the urn. He is amazed and describes each scene. The first scene tells a story through pictures that is set in Greece, either in Tempe or Arcady. The narrator asks many questions. He wonders whether the images represent men or gods. He also wonders what is going on in the illustration and whether it is a scene of pursuit, struggle, or ecstasy. The second scene is that of a young man playing the pipe beneath the trees. The man is similar to the leaves on the tree in that they are both fixed in time and will never die. The songs of this “happy melodist” and the “happy boughs” of the tree will live forever. The third scene is of a young lover who is very close to kissing his maiden. His maiden...

Words: 763 - Pages: 4

Premium Essay

Immortal Beloved

...Immortal Beloved The Immortal Beloved is by far one of the most moving and inspirational movies I have seen. The reason I say this is because throughout the movie Ludwig van Beethoven’s music defines the mood of each and every scene. For example, in the very beginning of the movie where they were showing Beethoven’s funeral they were using a very slow tempo and dramatic sounds in order to show the gloomy and upsetting atmosphere that was surrounding this particular scene. I think just by using the emotions of the people and further expressing it with his music accentuates everything to make it all fall in together, without it; it would be just a plain scene with people talking no emotions or anything. Throughout the film, the director showed and expressed the struggles that Beethoven had to endure due to his deafness. When they are trying to show the struggle that Beethoven has to endure with his deafness I noticed that they started to play a little more faster, and then I believe Beethoven could see what they were playing and that made him enjoy the music that much more. In the part where Beethoven was secretly playing so that no one could see him play, he put his head down on the piano because I believe he was trying to feel the vibrations of the piano in order to feel his music. I think that by just showing how he could love the music even though he had no way of ever hearing it shows the superior capability and love he had for music. Beethoven’s music...

Words: 920 - Pages: 4

Premium Essay

Eve Of St. Agnes

...This aspiration to be like Shakespeare appears in other works of Keats. The story told in “the Eve of St. Agnes” greatly resembles the story of Romeo and Juliet, yet the lovers in Keats story, Porphyro and Madeline, do not meet as tragic of a fate as Romeo and Juliet do. Though Romeo and Juliet’s love is based in reality, while Porphyro and Madeline's love is half coerced by Porphyro and half in Madeline's dream state then real life. Even the secondary characters within “the Eve of St. Agnes” remind the reader vaguely of other characters from Romeo and Juliet. Angela, who plays the middleman between Madeline and Porphyro, strongly resembles the Nurse, who does the same job for Romeo and Juliet. Even the Beadsman, who is only at the begin and...

Words: 328 - Pages: 2

Free Essay

Literature

...wordsworth-optimism keats-skeptical arts are really powerful.l what's the story behind the poem?? trigger the imagination. urn has the power to create our imagination. I. THOU still unravish’d bride of quietness, Thou foster-child of silence and slow time, Sylvan historian, who canst thus express A flowery tale more sweetly than our rhyme: What leaf-fring’d legend haunts about thy shape Of deities or mortals, or of both, In Tempe or the dales of Arcady? What men or gods are these? What maidens loth? What mad pursuit? What struggle to escape? What pipes and timbrels? What wild ecstasy? II. Heard melodies are sweet, but those unheard Are sweeter; therefore, ye soft pipes, play on; Not to the sensual ear, but, more endear’d, Pipe to the spirit ditties of no tone: Fair youth, beneath the trees, thou canst not leave Thy song, nor ever can those trees be bare; Bold Lover, never, never canst thou kiss, Though winning near the goal - yet, do not grieve; She cannot fade, though thou hast not thy bliss, For ever wilt thou love, and she be fair! III. Ah, happy, happy boughs! that cannot shed Your leaves, nor ever bid the Spring adieu; And, happy melodist, unwearied, For ever piping songs for ever new; More happy love! more happy, happy love! For ever warm and still to be enjoy’d, For ever panting, and for ever young; All breathing human passion far above, That leaves a heart high-sorrowful and cloy’d, A burning forehead, and a parching tongue. IV. Who are these coming to the sacrifice?...

Words: 1956 - Pages: 8

Free Essay

Keats Analysis

...A Frozen State of Love The poem, “Ode to a Grecian Urn” written by English Romantic poet, John Keats is one of the five ‘great odes’ of 1819. Keats describes the romantic, powerful reaction that overcomes his thoughts from staring at a piece of old pottery, which turns into a never ending love story. When analyzing the work, it is evident that literary devices such as imagery, metaphors and symbolism are used to depict the speakers’ view of this magical urn. Imagery flows through this poem like water through a stream. In the third stanza, the speaker compares the two lovers and the urn itself. “that cannot shed Your leaves, nor ever bid the Spring adieu; And, happy melodist, unwearied, For ever piping songs new;(Gioia and Kennedy vol. 4, pg. 477)”. Keats uses the example of a tree that cannot lose its leaves nor can it grow new ones in the spring to show the frozen state of love that these lovers remained trapped in. Another example of imagery comes from the fifth stanza when Keats says, “O Attic shape! Fair attitude! With brede Of marble men and maidens overwrought, with forest branches and the trodden weed;(Gioia and Kennedy vol.4, pg. 477)”. Keats begins to describe the shape of the urn and uses imagery to describe “marble men” and “maidens” that form a type of braid to explain the urn’s physical attributes. These examples allow the audience to form a mental picture of what Keats is describing. Which allows the audience to perceive a better understanding of the points...

Words: 778 - Pages: 4

Free Essay

Imagination

...------------------------------------------------- Ode on a Grecian urn ------------------------------------------------- (Ode = Lovprisning) ------------------------------------------------- (digter)jeg → ? ------------------------------------------------- Jeg → verden↔ ophøjet objekt ------------------------------------------------- Sum: Objektiv romantik ------------------------------------------------- ”a poet has no identity” ------------------------------------------------- “a poet is the most unpoetical of anything in existence; because he has no identity – he is continually in for - and filling some other body – the sun, the moon, the sea and men and women who are creatures of impulse are poetical and have about them an unchangeable attribute – the poet has none; no identity – he is certainly the most unpoetical of all Gods creatures. If then he has no self, and if I am a poet, where is the wonder that I say would write no more? Might I not at that very instant [have] been cogitating on the characters of Saturn and Ops? ------------------------------------------------- ------------------------------------------------- ------------------------------------------------- John Keats ------------------------------------------------- --> Negative capability --> Poet(ical character) --> ------------------------------------------------- Wordsworthian/ egotistical sublime (ophøjet) ------------------------------------------------- Ode on a Grecian urn -------------------------------------------------...

Words: 351 - Pages: 2

Free Essay

Ode on a Grecian Urn

...and a few magazines. Keats was born on the 31 of October 1795 in Moorgate, London, England. On the night of the 15 of April 1804 Keats father was seriously injured by his horse and died the next day. Keats mother died of tuberculosis in March of 1809. Keats died of tuberculosis on the 23 of February 1821 in Rome, Italy, and now rests in the Protestant Cemetery. Romanticism is an artistic and intellectual movement that originated in Europe toward the end of the 18th century and in most areas was at its peak from the 1800’s to the 1850’s. Keats articulates a common Romantic belief that beauty is the path to truth. He finds his beauty in his poem “Ode on a Grecian Urn” in the characters, music, and setting. One way that Keats shows his beauty is through the characters in his poem “Ode on a Grecian Urn”. We know from the title this is an ode about a Grecian urn. The first four lines serve to present the urn first as a bride, then as a foster-child, then as a historian. Keats calls the urn an “unravish’d bride of quietness” because it has existed for centuries without undergoing any changes as it sits quietly on a shelf or table. The urn looks new and pure although it is very old. He also calls it a “foster-child of silence and time” because it is has been adopted by silence and time, parents who have conferred on the urn eternal stillness. It no longer exists in the original circumstances in which it was created. In addition, Keats refers to the urn as a “sylvan historian” because...

Words: 829 - Pages: 4

Free Essay

Beauty with the Romantics

...and in art. He writes and defines beauty: “A think of beauty is joy for ever” In John Keats, we have a remarkable contrast both with Byron and Shelley. He knows nothing of Byron’s stormy spirit of antagonism to the existing order of things and he had no sympathy with Shelley’s humanitarian real and passion for reforming the world. But Keats likes and worships beauty. In his Ode on a Grecian Urn, he expresses some powerful lines about his thoughts of beauty. This ode contains the most discussed two lines in all of Keats's poetry: “Beauty is truth, truth beauty," - that is all Ye know on earth, and all ye need to know.” The exact meaning of those lines is disputed by everyone; no less a critic than TS Eliot considered them a blight upon an otherwise beautiful poem. Scholars have been unable to agree to whom the last thirteen lines of the poem are addressed. Arguments can be made for any of the four most obvious possibilities, -poet to reader, urn to reader, poet to urn, poet to figures on the urn. The issue is further confused by the change in quotation marks between the original manuscript copy of the ode and the 1820 published edition. P. B. Shelley: Shelley expresses love as one of the God-like phenomena in human life and beauty is the intellectual beauty to him....

Words: 2503 - Pages: 11

Premium Essay

Wordsworth's Poetry

...he argues that the first principle of poetry should be pleasure, that the chief duty of poetry is to provide pleasure through a rhythmic and beautiful expression of feeling—for all human sympathy, he claims, is based on a subtle pleasure principle that is “the naked and native dignity of man.” Recovering “the naked and native dignity of man” makes up a significant part of Wordsworth’s poetic project, and he follows his own advice from the 1802 preface. Wordsworth’s style remains plain-spoken and easy to understand even today, though the rhythms and idioms of common English have changed from those of the early nineteenth century. Many of Wordsworth’s poems (including masterpieces such as “Tintern Abbey” and the “Intimations of Immortality” ode) deal with the subjects of childhood and the memory of childhood in the mind of the adult in particular, childhood’s lost connection with nature, which can be preserved only in memory. Wordsworth’s images and metaphors mix natural scenery, religious symbolism (as in the sonnet “It is a beauteous evening, calm and...

Words: 473 - Pages: 2

Free Essay

Shelley and Keats Poem Analysis

...Assignment #4 1. Percy Bysshe Shelley is criticizing the British monarchy in lines three and six. In line three, he talks about the prince as “mud from a muddy spring.” Thus, he believes that the prince will fail England as a ruler because he is very similar to his father. Also, in line six, Shelley suggests that the monarchy is a leech that feeds of the people of England. The monarchy has no emotions and takes advantage of the labor of the poor in order to sustain the ruling class. 2. At the end of the poem, Shelley states that “unrepealed” laws “are graves, from which a glorious Phantom may Burst” in order to suggest the start of a revolution. The “glorious Phantom” is a new start that will help England rise up from the tyranny of the monarchy. The fact that the “glorious Phantom” comes from “graves” is to instill hope in the people of England. Shelley ends his poem on an optimistic tone in order to emphasize that, even in the worst situations, something beautiful will appear. 3. According to the poem “Ozymandias,” the remains of the statue of Ozymandias is abandoned and alone with nothing but “level sands” that stretch around it. The present, dilapidated condition of the statue is used by Shelley to highlight the fact that even the most powerful rulers can be forgotten. The king originally wanted the statue to be a statement of his legacy because he declared that he was “king of kings: Look on my works, ye mighty, and despair!” However, in the present day, the king...

Words: 1318 - Pages: 6