SctcCh0st

download SctcCh0st

of 16

Transcript of SctcCh0st

  • 8/22/2019 SctcCh0st

    1/16

    Introduction

    Practical Examples

    MATLAB codes

    SCIENTIFIC COMPUTING

    FuSen Lin ()

    Department of Computer Science & EngineeringNational Taiwan Ocean University

    Scientific Computing, Fall 2007

    FuSen Lin Scientific Computing

  • 8/22/2019 SctcCh0st

    2/16

    Introduction

    Practical Examples

    MATLAB codes

    Chapter 0: Introduction

    Introduction to Scientific Computing

    Three Practical Examples

    Examples of MATLAB codes

    FuSen Lin Scientific Computing

  • 8/22/2019 SctcCh0st

    3/16

    Introduction

    Practical Examples

    MATLAB codes

    What is Scientific Computing?

    To solve diversely mathematical problems which arise in

    science and engineering.To design robust algorithms for finding approximate

    solutions to the given problem with any powerful tools

    (software).

    Practical problems = Mathematical models= Numerical algorithms = (Reasonably approximate)solutions

    FuSen Lin Scientific Computing

  • 8/22/2019 SctcCh0st

    4/16

    Introduction

    Practical Examples

    MATLAB codes

    The Objective of Learning Scientific Computing?

    To learn the potentialities of modern computational

    methods for solving numerical problems arisen in science

    and engineering.

    To give students an opportunity to hone their skills in

    programming and problem solving.

    To help students understand the important subject of

    errorsthat inevitably accompany scientific computing and

    to arm them with methods for detecting, predicting, and

    controlling these errors.To familiarize students with the intelligent use of powerful

    software systems such as MATLAB, Maple, and

    Mathematica.

    FuSen Lin Scientific Computing

  • 8/22/2019 SctcCh0st

    5/16

    Introduction

    Practical Examples

    MATLAB codes

    The Goal of Scientific Computation

    Numerical computations Pursue

    Efficiency: the computational speed of a problem.Liability: the accuracy of computational results (within thegiven error tolerance).Stability: the stability of an algorithm and its applicablerange.

    if use different algorithms for a problem, we may have

    different accuracy, different speed, different applicable

    range.

    If we use the same algorithm with different procedures(coding) then the running time and accuracy may not be

    the same.

    We shall study and pursue the best algorithms.

    FuSen Lin Scientific Computing

  • 8/22/2019 SctcCh0st

    6/16

    Introduction

    Practical Examples

    MATLAB codes

    Problems in Scientific Computing

    Finding-root problemsInterpolation problems

    The method of least squares

    Numerical Differentiation and Integration

    Spline Approximation

    Methods of Solving Linear Systems

    Matrix Computations

    Numerical solutions to ODE(Initial-Value Problems and

    Boundary-Value Problems)

    Numerical solutions to PDE (Eulers mehod, Multistepmethods, Rung-Kutta methods, Finite Difference Methods,

    or Finite Element Method)

    Optimization problems

    Other computational problems

    FuSen Lin Scientific Computing

    I t d ti E l 1

  • 8/22/2019 SctcCh0st

    7/16

    Introduction

    Practical Examples

    MATLAB codes

    Example 1

    Example 2

    Example 3

    Three Practical Examples

    The finding-root Problem

    The electrical circuit problem

    The Least Squares Problem

    FuSen Lin Scientific Computing

    Introduction Example 1

  • 8/22/2019 SctcCh0st

    8/16

    Introduction

    Practical Examples

    MATLAB codes

    Example 1

    Example 2

    Example 3

    A finding-root problem

    ExampleAn electric power cable is suspended (at points of equal

    hight) from two towers that are 100 meters apart. The cable

    is allowed to dip 10 meters in the middle. How long is the

    cable? (It is known that the curve assumed by a suspended

    cable is a Catenary()).

    Proof.

    Let x be the distance between each tower and the center of two

    towers. When the y-axis passes through the lowest point of thecable, the curve can be expressed as

    y = coshx

    .

    Here is a parameter to be determined. (continuing ).FuSen Lin Scientific Computing

    Introduction Example 1

  • 8/22/2019 SctcCh0st

    9/16

    Introduction

    Practical Examples

    MATLAB codes

    Example 1

    Example 2

    Example 3

    A finding-root problem (continuing )

    Proof.

    (Continuing ) The conditions of this problem are

    y(50) = y(0) + 10. The problem becomes to solve the equation

    cosh

    50

    = + 10

    for . Applying the methods of locating roots, we can obtain

    = 126.632.

    From the equation of catenary, the length of cable (arc length)

    is easily computed by the method of calculus (numerical

    integration) to be 102.619 meters (see MATLAB DEMO).

    FuSen Lin Scientific Computing

    Introduction Example 1

  • 8/22/2019 SctcCh0st

    10/16

    Introduction

    Practical Examples

    MATLAB codes

    Example 1

    Example 2

    Example 3

    The Electrical Circuit Problem

    ExampleA simple electrical network contains a number of resistances and a

    single source of electromotive force (a battery) as shown in the

    following figure.

    FuSen Lin Scientific Computing

    Introduction Example 1

  • 8/22/2019 SctcCh0st

    11/16

    Introduction

    Practical Examples

    MATLAB codes

    Example 1

    Example 2

    Example 3

    The Electrical Circuit Problem

    Using Kirchhoffs laws and Ohms law, we can write a system

    of equations that govern this circuit. If x1, x2, x3, and x4 are theloop currents as shown, then the equations are

    15x1 2x2 6x3 = 3002x1 + 12x2 4x3 x4 = 06x

    1 4x

    2+ 19x

    3 9x

    4= 0

    x2 9x3 + 21x4 = 0

    Systems of equations like this, even those that contain hundredunknowns, can be solved by using the methods of solving linear

    systems.

    6 2 2 40 4 2 2

    0 0 2 50 0 0 3

    x1x2x3x4

    =

    16693

    The solution is x1 = 26.5, x2 = 9.35, x3 = 13.3, x4 = 6.13.

    FuSen Lin Scientific Computing

    Introduction Example 1

  • 8/22/2019 SctcCh0st

    12/16

    Introduction

    Practical Examples

    MATLAB codes

    Example 1

    Example 2

    Example 3

    The Least Squares Problem

    ExampleA physical experiment: Surface tension S in a liquid is known to

    be a linear function of temperature T. For a particular liquid,

    measurements have been made of the surface tension at

    certain temperatures. The results were

    T 0 10 20 30 40 80 90 95

    S 68.0 67.1 66.4 65.6 64.6 61.8 61.0 60.0

    How can the most probable values of the constants in the

    equation S = aT + b be determined?

    Methods for solving such problems are called the least

    squares methods.

    FuSen Lin Scientific Computing

    Introduction

  • 8/22/2019 SctcCh0st

    13/16

    Practical Examples

    MATLAB codes

    Solution of Example 1

    % solution of example 1

    syms x %

    f = inline(x*cosh(50/x)-x-10);

    lambda = fzero(f,100) % lambda = 126.6324

    r=fzero(x.*cosh(50./x)-x-10,130) % finding root

    syms a x %

    a = 126.6324*cosh(x/126.6324);

    s = (1+diff(a).2).0.5; % set up the arc length function

    I = vpa(int(s,-50,50)) % find the length by integration

    FuSen Lin Scientific Computing

    Introduction

  • 8/22/2019 SctcCh0st

    14/16

    Practical Examples

    MATLAB codes

    Solution of Example 3

    % Solution of Example3 for the least squares problem

    % An example of Script Files

    xdata = [0, 10, 20, 30, 40, 80, 90, 95]; %

    ydata = [68.0, 67.1, 66.4, 65.6, 64.6, 61.8, 61.0, 60.0];

    plot(xdata, ydata, o) % plot the datals = polyfit(xdata, ydata, 1); % call polyfit.m function

    a = ls(1); b = ls(2);

    d = a*xdata + b - ydata;

    phi = sum(d.2);

    x = 0:5:100;

    y = polyval(ls, x); % compute the values of yhold on

    plot(x, y,-r) % plot the curve of y

    disp([a, b, phi] = )

    [a, b, phi]

    FuSen Lin Scientific Computing

    Introduction

  • 8/22/2019 SctcCh0st

    15/16

    Practical Examples

    MATLAB codes

    Function Files

    function y = logsrs1(x, n)

    % Date: 3/12/2001, Name: Fusen F. Lin

    % This function computes log(2) by the series,

    % log(1+x)= x-x2/2+x3/3-x4/4+x5/5-..., for n terms.

    % Input : real x and integer n. Notice that:% the input x=1 to get log(2).

    % Output: the desired value log(1+x).

    tn = x; % The first term.

    sn = tn; % The n-th partial sum.

    for k = 1:1:n-1, % Use for-loop to sum the series.tn = -tn*x*k/(k+1); % compute it recursively.

    s n = s n + t n ;

    end

    y = sn; % Output the final sum.

    FuSen Lin Scientific Computing

    Introduction

  • 8/22/2019 SctcCh0st

    16/16

    Practical Examples

    MATLAB codes

    Some Web Sites

    The MathWorks, Inc. (MATLAB):http://www.mathworks.com.

    Massachusetts Institute of Technology:

    Department of EECS: http://www.eecs.mit.edu/grad/

    MIT Open Courses: http://ocw.mit.edu/index.htmlChinese Web Sites of Open Courses:

    http://www.myoops.org/twocw/mit/index.htm

    Department of Mathematics, MIT:

    http://math.mit.edu/research/index.html

    The Computing Laboratory of Oxford University:

    http://web.comlab.ox.ac.uk/oucl/

    Department of Computer Science, Cornell University:

    http://www.cs.cornell.edu/cv/

    FuSen Lin Scientific Computing