High Order Polynomial

Embed Size (px)

Citation preview

  • 8/13/2019 High Order Polynomial

    1/3

    Project 3 (Spring2012)

    Length of a Fifth Order Polynomial Curve

    The Project Statement:

    Consider a fifth order polynomial f(x) = poly5(coef,x) where coef lists the five

    coefficients and x varies from xleft to xright. The objective is to approximate its length

    (arclength). There are to be three cells.

    (a). The first cell will use input() to define coef, xleft and xright and generate a graph of

    f(x) in figure(1) (see lecture 15).

    (b). The second cell will approximate the length by using ginput() to select n points and

    sum the lengths of the corresponding chords in figure(2) (see lectures 16, 17 and EX7_15.m).

    (c). The third cell will approximate the length using the trapezoid rule, a for-loop and the

    arclength integral (see lectures 17 and 18).

    The Math Model:

    Cell two is to use the formula for the length of chord between two points (x(i),y(i)) and(x(i+1),y(i+1))

    length of chord i = sqrt(dx^2 + dy^2) where dx = x(i+1)-x(i) and dy = y(i+1)-y(i).

    Cell three is to use the trapezoid rule to approximate the arclength integral

    F(x)dx where F(x) = sqrt(1 + (df/dx)2)

    The areas of the trapezoids are

    (F(x(i)) + F(x(i+1)) (x(i+1) - x(i))/2.

  • 8/13/2019 High Order Polynomial

    2/3

    Methods of Solution:

    The lengths of the chords in cell two should be added using the command sum(). Do this

    three times using the cell mode and n = 5, 10 and 15 points. The trapezoid areas in cell three

    should be added using a for-loop. Do this three times using the cell mode and n = 15, 30 and 60

    trapezoids. Compare your six approximations.

    Structure of the Report:

    problem or application and objectives (5 points) model and derivation (5 points) general description of the Matlab with three cells (5 points) experimentation with of the models in cells two and three (15 points) Matlab code in a separate file (70 points)

    Structure of the Matlab Code:

    documentation header and comment lines (15 points) inputs section (15 points) execution section (25 points) output section (15 points)

    Submissions:

    may work in groups of one, two or three one *.doc or *.docx file with report, include allnames in group one *.m code file that I can execute electronic via moodle deadline is 12:05 AM, Friday, March 23 (midnight on Thursday)

    ******************************************************************************

    EX7_15.m is similar to what was generated in lectures 16 and 17:

    % Thi s code has f our cel l s. % The f i r st cel l gr aphs a par abol i c cur ve of pr oj ecti l e. % The second cel l approxi mat es t he maxi mumhei ght and i mpact t i me. % The t hi r d cel l appr oxi mat es t he ar cl engt h (di st ance t r avel ed) .% The f our t h cel l approxi mat es t he area above ground and bel ow curve.

    %%% CELL ONE: Exer ci se 7. 15

  • 8/13/2019 High Order Polynomial

    3/3

    %cl ear ; cl f ( f i gure(1) ) ; cl f ( f i gure(2) ) ; cl c; di sp( ' Probl em7. 15: gr aph h( t ) = - ( 9. 8/ 2) t 2 + 125t + 500' ) t i meend = i nput ( ' ent er end t i me gr eat er t han 30 = ' ) t = 0: . 1: t i meend; hei ght = - ( 9. 8/ 2) *t . 2 + 125*t + 500; f i gur e( 1) pl ot ( t , hei ght ) hol d ondi sp( ' End of CELL ONE' ) %%% CELL TWO: maxi mum hei ght and t i me when mass hi t s t he ground%di sp( ' choose thr ee poi nt s near maxi mum hei ght ' ) [ t _pt h_pt ] = gi nput ( 3) di sp( ' sel ect max hei ght ' ) max_hei ght = i nput ( ' ent er l ar gest h_pt = ' ) di sp( ' t i me sel ect t i me f or max hei ght ' ) max_t i me = i nput ( ' ent er t _pt t hat gi ves l ar gest hei ght = ' ) %

    di sp( ' choose thr ee poi nt s wher e the hei ght i s near zero' ) [ t t _pt hh_pt ] = gi nput ( 3) di sp( ' sel ect zer o hei ght and t i me' ) i mpact _t i me = i nput( ' ent er t i me where hei ght i s cl osest t o zero = ' ) di sp( ' End of CELL TWO' ) %%% CELL THREE: approxi mat e ar cl ength%f i gur e( 2) pl ot ( t , hei ght ) hol d onnumpoi nt s = i nput ( ' ent er number of poi nts on par abol a above zer o = ' ) di sp( ' sel ect poi nt s on par abol a above zero hei ght ' ) [ xx yy] = gi nput ( numpoi nt s) pl ot ( xx, yy) dx = di f f ( xx) ; % l i st s al l t he changes i n xxdy = di f f ( yy) ; % l i st s al l t he changes i n yydi st = sqr t ( dx. 2 + dy. 2) ; % comput es al l t he l engt hs of t he chordsdi sp( ' l engt hs of t he chor ds' ) f pr i nt f ( ' %8. 2f \ n' , di st ) ar cl engt h = sum( di st ) ; % adds t hese l engt hsdi sp( ' appr oxi mat e ar cl engt h i s ' )f pr i nt f ( ' %8. 2f \ n' , ar cl engt h)di sp( ' End of CELL THREE' ) %%% CELL FOUR: appr oxi mat e area%

    % compute the area of each t r apezoi df or i = 1: ( numpoi nt s- 1) t r ap( i ) = . 5*( yy( i ) + yy( i +1) ) *( xx( i +1) - xx( i ) ) ;

    enddi sp( ' ar ea of t he tr apezoi ds' ) f pr i nt f ( ' %10. 2f \ n' , t r ap' )di sp( ' appr oxi mat e t ot al ar ea' ) approx_area = sum( t r ap) ; f pr i nt f ( ' %10. 2f \ n' , appr ox_area)di sp( ' End of CELL FOUR' )