Ber - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Ber

Description:

Numeriska ber kningar i Naturvetenskap och Teknik Repetition of loops and conditions etc 2. Solving equations with computer 3. Differential equations part 1 – PowerPoint PPT presentation

Number of Views:92
Avg rating:3.0/5.0
Slides: 29
Provided by: joak6
Category:
Tags: ber | equations | solving | step

less

Transcript and Presenter's Notes

Title: Ber


1
Numeriska beräkningar i Naturvetenskap och Teknik
  1. Repetition of loops and conditions etc

2. Solving equations with computer
3. Differential equations part 1
2
Numeriska beräkningar i Naturvetenskap och Teknik
  1. Conditions and loops etc

3
Numeriska beräkningar i Naturvetenskap och Teknik
The for loop repeats a fixed number of
times for i00.110 startstepstop statement
s end
--------------------------------------------------
---------- Example The size of generation of an
animal population limited by resources can be
modelled with the logistics equation X(t1)
k X(t) ( 1 - X(t)) where t is the
generations number, X(t) the size (0 to 1) of
generation t, k gives the growth rate without
competition and the available resources are
proportional to (1-X(t))
4
Numeriska beräkningar i Naturvetenskap och Teknik
The while loop runs until condition not
met. while ilt1000 difflt0.4 update counter
i calculate diff statements end
Example Same as the for loop model. Now we run
until the difference between two generations is
larger than 40 but we run for at most 1000
generations i.e we have a combined condition.
5
Numeriska beräkningar i Naturvetenskap och Teknik
Matlab notation for vectors and matrices For
two vectors a and b a b is the scalar
product a . is the elementwise product a b
dot(a,b) ----------------------------------------
-------------------
Demo x0.50.60.7 sin(x)
sin(0.5)sin(0.6)sin(0.7) y x sin(x)
?, works ? Y x . sin(x) ?
6
Numeriska beräkningar i Naturvetenskap och Teknik
Plotting and saving
Example Plot x sin (x) for x from 0 to 100 in
steps of 0.1 Label axis Add name to plot Save
to jpg
7
Numeriska beräkningar i Naturvetenskap och Teknik
2D plots and meshes
Example Plot sin (x2 y2) for the grid x-2
to 2 and y-2 to 2 with steps of 0.05 in each
direction. X,Y meshgrid(-20.052,-20.052)
How do X and Y look like? Z sin(X.2
Y.2) Why do we use . ? mesh(X,Y,Z) Plots the
surface, other commands surf etc.
8
Numeriska beräkningar i Naturvetenskap och Teknik
  1. Solving equations

9
Numeriska beräkningar i Naturvetenskap och Teknik
Discretization
10
Numeriska beräkningar i Naturvetenskap och Teknik
An example using graphs
11
Numeriska beräkningar i Naturvetenskap och Teknik
A numerical exemple gtgt bisection method
Sign change
Half of the interval...
again...
and again...
12
Numeriska beräkningar i Naturvetenskap och Teknik
Bisection
13
Numeriska beräkningar i Naturvetenskap och Teknik
Bisection method A clear limitation of the
method is that the new approximation does not
take into account the value of the function for
the latest x-value it was calculated
at. Compare which gives So, we have
stepped two times but are hardly any closer to
the solution than we were two steps earlier(the
sign has changed though) How can we use the
knowledge we have of the value of the function in
order to guess a new better value?
14
Numeriska beräkningar i Naturvetenskap och Teknik
Secant method
Equation of secant
Root
x2, approximation
Iteration formula!
15
Numeriska beräkningar i Naturvetenskap och Teknik
The secant method
Code examples
16
Numeriska beräkningar i Naturvetenskap och Teknik
Newton-Raphsons method
Let the step between xn and xn-1 tend to zero...
or the eq. of the tangent
17
Numeriska beräkningar i Naturvetenskap och Teknik
Iteration principle
1-point method
2-point method
18
Numeriska beräkningar i Naturvetenskap och Teknik
19
Numeriska beräkningar i Naturvetenskap och Teknik
Our exemple once more
Solve for the root
i.e.
is a possibility. Are there others?
yes, infinitely many!
20
Numeriska beräkningar i Naturvetenskap och Teknik
21
Numeriska beräkningar i Naturvetenskap och Teknik
The mean value theorem
but
i.e.
or
22
Numeriska beräkningar i Naturvetenskap och Teknik
The relative error between two iterations
If G(?) is less than 1 the iteration will
converge. ----------------------------------------
--------------------- If xn och xn1 are close to
a then ? is also an approximation for a, i.e. if
G(?)lt1 around the root a, the iteration will
Converge. The convergence is quicker the smaler
G is in the surrounding of a. ------------------
-------------------------------------------
How can this be used in order to optimize how we
write the iteration formula?
23
Numeriska beräkningar i Naturvetenskap och Teknik
Let us rewrite f(x)0
that is
Assume that the start value is a good
approximation for the root
which leads to
24
Numeriska beräkningar i Naturvetenskap och Teknik
Newton Raphsons modified method
Our exemples
Applying Newton Raphsons modified method
25
Numeriska beräkningar i Naturvetenskap och Teknik
Error propagation
26
Numeriska beräkningar i Naturvetenskap och Teknik
Error propagation
27
Numeriska beräkningar i Naturvetenskap och Teknik
Discretization and error propagation
28
Numeriska beräkningar i Naturvetenskap och Teknik
Demo Newton-Raphsons modifierade metod etc.
Write a Comment
User Comments (0)
About PowerShow.com