SlideShare una empresa de Scribd logo
1 de 9
Descargar para leer sin conexión
AMTH250                        Assignment 4
       Due date: 27th August 2012
                Solutions

                                August 10, 2012


Question 1
The following data are related to the life expectation of citizens of two countries:
                                1975    1980    1985    1990
                        Tanab   72.8    74.2    75.2    76.4
                        Sarac   70.2    70.2    70.3    71.2

  1. Use the interpolating polynomial of degree three to estimate the life ex-
     pectation in 1977, 1983, and 1988.
  2. Repeat the computations using now the cubic spline interpolation.
  3. Compare the above two results.

octave:1> year=[1975 1980 1985 1990];
octave:2> tanab=[72.8 74.2 75.2 76.4];
octave:3> sarac=[70.2 70.2 70.3 71.2];
octave:4> ctanab=polyfit(year, tanab,3);
octave:5> csarac=polyfit(year, sarac,3);
octave:6> esttanab=polyval(ctanab, [1977 1983 1988])
esttanab =

   73.446      74.810     75.858

octave:7> estsarac=polyval(csarac, [1977 1983 1988])
estsarac =

   70.233      70.203     70.699


The estimated values in 1977, 1983 and 1988 are
   73.446 74.810 75.858 for Tanab, and
   70.233 70.203 70.699 for Sarac.




                                         1
Question 2
This is an interpolation problem. It solved by constructing the basis matrix and
solving a linear system.
octave:> x = [-2 -1 0 1 2]’;
octave:> y = [125.948 7.673 -4 -14.493 -103.429]’;
octave:> aa = [exp(-2*x) exp(-x) ones(5,1) exp(x) exp(2*x)];
octave:> coeffs = aay
coeffs =
   3.0000
  -4.9998
  -1.0004
   1.0003
  -2.0000

Thus the interpolating function is

                      y ≈ 3e−2x − 5e−x − 1 + ex − 2e2x .

Question 3
First we compute the interpolating functions:
octave:>   x = [0 0.01 0.04 0.09 0.16 0.25]’;
octave:>   y = [0 0.1 0.2 0.3 0.4 0.5]’;
octave:>   p = polyfit(x, y, 5);
octave:>   cs = interp1(x, y, ’spline’, ’pp’);
octave:>   pc = interp1(x, y, ’pchip’, ’pp’);
   Plotting the errors, i.e. the difference between the interpolating function
     √
and x we see that the pchip cubic is the most accurate over most domain.
   Restricting attention to the interval [0, 0.01] shows that they are all about
equally inaccurate over that range. The reason for this is that the derivative
   √
of x is infinite at x = 0 making approximation by a function with a finite
derivative at x = 0 difficult near x = 0.




                                       2
Polynomial                                                  Cubic Spline
 0.03                                                            0.03



 0.02                                                            0.02



 0.01                                                            0.01



    0                                                               0



 -0.01                                                           -0.01



 -0.02                                                           -0.02



 -0.03                                                           -0.03
         0   0.05     0.1            0.15     0.2    0.25                0   0.05     0.1         0.15     0.2    0.25




                        Pchip Cubic
 0.03



 0.02



 0.01



    0



 -0.01



 -0.02



 -0.03
         0   0.05     0.1            0.15     0.2    0.25




               Figure 1: Errors in interpolating functions.



                            Polynomial                                                  Cubic Spline
    0                                                               0



-0.005                                                          -0.005



 -0.01                                                           -0.01



-0.015                                                          -0.015



 -0.02                                                           -0.02



-0.025                                                          -0.025
         0   0.002   0.004           0.006   0.008   0.01                0   0.002   0.004        0.006   0.008   0.01




                        Pchip Cubic
    0



-0.005



 -0.01



-0.015



 -0.02



-0.025
         0   0.002   0.004           0.006   0.008   0.01




     Figure 2: Errors in interpolating functions in [0, 0.01].




                                                            3
Question 4


                             Cubic Spline                                       1st Derivative
         12                                                    3



         10
                                                               2


          8
                                                               1

          6

                                                               0
          4


                                                               -1
          2



          0                                                    -2
               1   2     3         4          5   6   7             1   2   3         4          5   6   7




                             2nd Derivative                                     3rd Derivative
          8                                                    8


                                                               6
          6

                                                               4
          4

                                                               2
          2
                                                               0

          0
                                                               -2

          -2
                                                               -4


          -4                                                   -6
               1   2     3         4          5   6   7             1   2   3         4          5   6   7




                       Figure 3: Cubic spline and its derivatives.



                              Pchip Cubic                                       1st Derivative
         12                                                    3



         10                                                   2.5



          8                                                    2



          6                                                   1.5



          4                                                    1



          2                                                   0.5



          0                                                    0
               1   2     3         4          5   6   7             1   2   3         4          5   6   7




                             2nd Derivative                                     3rd Derivative
         10                                                    5




          5                                                    0




          0                                                    -5




          -5                                                  -10




         -10                                                  -15
               1   2     3         4          5   6   7             1   2   3         4          5   6   7




                       Figure 4: Pchip cubic and its derivatives.




                                                          4
From the graphs we see the defining conditions for a cubic spline are satisfied:

  1. From the first plot the function interpolates the data.
  2. From the second and third plots the function has continuous first and
     second derivatives.
  3. From the fourth plot the function has constant third derivative on each
     subinterval. It follows that the function is a cubic polynomial on each
     subinterval.
  4. The ‘not-a-knot’ condition shows up in the third derivative is the same on
     the first and second subintervals and on the second last and last subinter-
     vals.

   The defining conditions for a pchip cubic are also satisfied:

  1. From the first plot the function interpolates the data.
  2. From the second plot the function has continuous first derivative. The
     third plot shows that the second derivative is discontinuous.
  3. From the fourth plot the function has constant third derivative on each
     subinterval. It follows that the function is a cubic polynomial on each
     subinterval.
  4. In this example the data is monotonic, a property shared by the pchip
     cubic. This implies that the derivative of the pchip cubic does not change
     sign. The second plot shows that derivative is everywhere positive.

Question 5
Write the equations in matrix form and solve the least squares problem with
the backslash operator.
octave:> A = [1 0 0 0
>0 1 0 0
>0 0 1 0
>0 0 0 1
>1 -1 0 0
>1 0 -1 0
>1 0 0 -1
>0 1 -1 0
>0 1 0 -1
>0 0 1 -1];
octave:> y = [2.95 1.74 -1.45 1.32 1.23 4.45 1.61 3.21 0.45 -2.75]’;
octave:> x = Ay
x =
   2.9600
   1.7460
  -1.4600
   1.3140
These values are within ±0.01 of the direct measurements.


                                       5
Question 6
Here is a script to compute and plot the fitted functions:
x = 1:10;
y = [27.7 39.3 38.4 57.6 46.3 54.8 108.5 137.6 194.1 281.2];
lx =log(x);
ly =log(y);
p = polyfit(x, y, 2);
ce = polyfit(x, ly, 1);
ae = exp(ce(2));
ke = ce(1);
fe = @(x) ae*exp(ke*x);
cp = polyfit(lx, ly, 1);
ap = exp(cp(2));
kp = cp(1);
fp = @(x) ap*x.^kp;

clf()
xx = linspace(1, 10, 201);
plot(x,y,’or’)
hold on
plot(xx, polyval(p,xx))
plot(xx, fe(xx),’k’)
plot(xx, fp(xx), ’g’)
hold off


           300
                                                                   Quadratic
                                                         Exponential Function
                                                             Power Function




           250




           200




           150




           100




            50




             0
                 0      2          4           6           8                    10




     From this we see that the power function gives a poor fit, but visually there
is little to chose between the quadratic polynomial and the exponential function.


                                       6
Part of the reason the power function y = axp gives such a poor fit is that when
p > 0 the graph of the function must pass through the origin.
   Plotting the residuals
res1 = y - polyval(p,x);
res2 = y - fe(x);
res3 = y - fp(x);
Shows that the quadratic polynomial has the smallest residuals. This is con-
firmed by the norms
octave:> norm(res1)
ans = 43.364
octave:> norm(res2)
ans = 70.894
octave:> norm(res3)
ans = 151.69


           150
                                                                   Quadratic
                                                         Exponential Function
                                                             Power Function




           100




           50




            0




           -50
                 0      2          4           6           8                    10




                     Figure 5: Residuals of fitted functions.


   A semilog plot of the data indicates that an exponential function function
may give a good description of the data. When working with the semilog data,
the appropriate residuals are the differences log yi − log f (xi )
lres1 = ly - log(polyval(p,x));
lres2 = ly - log(fe(x));
lres3 = ly - log(fp(x));
   Using the semilog scale that the exponential function has the smallest resid-
uals. This is confirmed by the norms


                                       7
octave:> norm(lres1)
ans = 0.87342
octave:> norm(lres2)
ans = 0.66707
octave:> norm(lres3)
ans = 1.1785


                                  Fitted Functions                                          Semilog Residuals
           6                                                             0.8
                                                   Quadratic                                                  Quadratic
                                         Exponential Function                                       Exponential Function
                                             Power Function                                             Power Function


                                                                         0.6
          5.5




                                                                         0.4

           5




                                                                         0.2


          4.5



                                                                           0



           4


                                                                         -0.2




          3.5

                                                                         -0.4




           3
                                                                         -0.6




          2.5                                                            -0.8
                0   2             4             6          8    10              0   2        4            6          8     10




       Figure 6: Semilog plot of fitted functions and semilog residuals.


   A log-log plot of the data indicates that a power function would not be
expected to give a good fit to the data.

                         6




                        5.5




                         5




                        4.5




                         4




                        3.5




                         3
                              0                      0.5        1           1.5         2                 2.5




                                  Figure 7: Log-log plot of the data



                                                                     8
In summary
1. The power function does not give a good representation of the data.

2. The quadratic polynomial and exponential function give reasonable rep-
   resentations of the data.
3. Examining the residuals would indicate that the quadratic gives the best
   representation.

4. A semilog plot indicates that an exponential function may give a good
   representation of the data. Another reason for preferring the exponential
   is that it is monotonic and we may believe from examining the data that
   the underlying trend is monotonic. The exponential function is monotonic,
   the quadratic polynomial is not.




                                    9

Más contenido relacionado

La actualidad más candente

Modul matematik( panjang, berat, isipadu cecair)
Modul matematik( panjang, berat, isipadu cecair)Modul matematik( panjang, berat, isipadu cecair)
Modul matematik( panjang, berat, isipadu cecair)soulmoon
 
Copy Of Consumer
Copy Of ConsumerCopy Of Consumer
Copy Of ConsumerPaul Bujak
 
Ukázkový report - SolidVision
Ukázkový report - SolidVisionUkázkový report - SolidVision
Ukázkový report - SolidVision3dskenovani
 
Regulations As a "Panacea": Exploring the Consequences
Regulations As a "Panacea": Exploring the ConsequencesRegulations As a "Panacea": Exploring the Consequences
Regulations As a "Panacea": Exploring the ConsequencesMercatus Center
 
Mlb graphs slide deck
Mlb graphs slide deckMlb graphs slide deck
Mlb graphs slide deckKevin Teh
 
VaR of Operational Risk
VaR of Operational RiskVaR of Operational Risk
VaR of Operational RiskRahmat Mulyana
 
Laboratorio valoración de cartera resolución enviar
Laboratorio valoración de cartera resolución enviarLaboratorio valoración de cartera resolución enviar
Laboratorio valoración de cartera resolución enviarEdlin Rodriguez
 

La actualidad más candente (16)

Small Business Energy Efficiency: Roadmap to Program Design
Small Business Energy Efficiency: Roadmap to Program DesignSmall Business Energy Efficiency: Roadmap to Program Design
Small Business Energy Efficiency: Roadmap to Program Design
 
7 quality tools
7 quality tools7 quality tools
7 quality tools
 
Modul matematik( panjang, berat, isipadu cecair)
Modul matematik( panjang, berat, isipadu cecair)Modul matematik( panjang, berat, isipadu cecair)
Modul matematik( panjang, berat, isipadu cecair)
 
Fxdq
FxdqFxdq
Fxdq
 
Copy Of Consumer
Copy Of ConsumerCopy Of Consumer
Copy Of Consumer
 
Ukázkový report - SolidVision
Ukázkový report - SolidVisionUkázkový report - SolidVision
Ukázkový report - SolidVision
 
2009 Face Conference Ma Fiore
2009 Face Conference Ma Fiore2009 Face Conference Ma Fiore
2009 Face Conference Ma Fiore
 
Regulations As a "Panacea": Exploring the Consequences
Regulations As a "Panacea": Exploring the ConsequencesRegulations As a "Panacea": Exploring the Consequences
Regulations As a "Panacea": Exploring the Consequences
 
FY07 Master .xls
FY07 Master .xlsFY07 Master .xls
FY07 Master .xls
 
Mlb graphs slide deck
Mlb graphs slide deckMlb graphs slide deck
Mlb graphs slide deck
 
credit-suisse Restatement re
credit-suisse Restatement recredit-suisse Restatement re
credit-suisse Restatement re
 
VaR of Operational Risk
VaR of Operational RiskVaR of Operational Risk
VaR of Operational Risk
 
histograma
histograma histograma
histograma
 
Laboratorio valoración de cartera resolución enviar
Laboratorio valoración de cartera resolución enviarLaboratorio valoración de cartera resolución enviar
Laboratorio valoración de cartera resolución enviar
 
251109 Or
251109 Or251109 Or
251109 Or
 
Ejercicio 9
Ejercicio 9Ejercicio 9
Ejercicio 9
 

Destacado

Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)asghar123456
 
Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)asghar123456
 
Answers assignment 3 integral methods-fluid mechanics
Answers assignment 3 integral methods-fluid mechanicsAnswers assignment 3 integral methods-fluid mechanics
Answers assignment 3 integral methods-fluid mechanicsasghar123456
 
Answers assignment 4 real fluids-fluid mechanics
Answers assignment 4 real fluids-fluid mechanicsAnswers assignment 4 real fluids-fluid mechanics
Answers assignment 4 real fluids-fluid mechanicsasghar123456
 
Answers assignment 2 fluid statics-fluid mechanics
Answers assignment 2 fluid statics-fluid mechanicsAnswers assignment 2 fluid statics-fluid mechanics
Answers assignment 2 fluid statics-fluid mechanicsasghar123456
 
Answers assignment 5 open channel hydraulics-fluid mechanics
Answers assignment 5 open channel hydraulics-fluid mechanicsAnswers assignment 5 open channel hydraulics-fluid mechanics
Answers assignment 5 open channel hydraulics-fluid mechanicsasghar123456
 

Destacado (6)

Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)
 
Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)
 
Answers assignment 3 integral methods-fluid mechanics
Answers assignment 3 integral methods-fluid mechanicsAnswers assignment 3 integral methods-fluid mechanics
Answers assignment 3 integral methods-fluid mechanics
 
Answers assignment 4 real fluids-fluid mechanics
Answers assignment 4 real fluids-fluid mechanicsAnswers assignment 4 real fluids-fluid mechanics
Answers assignment 4 real fluids-fluid mechanics
 
Answers assignment 2 fluid statics-fluid mechanics
Answers assignment 2 fluid statics-fluid mechanicsAnswers assignment 2 fluid statics-fluid mechanics
Answers assignment 2 fluid statics-fluid mechanics
 
Answers assignment 5 open channel hydraulics-fluid mechanics
Answers assignment 5 open channel hydraulics-fluid mechanicsAnswers assignment 5 open channel hydraulics-fluid mechanics
Answers assignment 5 open channel hydraulics-fluid mechanics
 

Similar a Amth250 octave matlab some solutions (3)

adc converter basics
adc converter basicsadc converter basics
adc converter basicshacker1500
 
Machine learning projects with r
Machine learning projects with rMachine learning projects with r
Machine learning projects with rliyiou
 
Excel slide series - fractions introduction
Excel slide series -  fractions introductionExcel slide series -  fractions introduction
Excel slide series - fractions introductionPuworkUtara OnSlideshare
 
Las ม.2 ปีการศึกษา 2554
Las ม.2 ปีการศึกษา 2554Las ม.2 ปีการศึกษา 2554
Las ม.2 ปีการศึกษา 2554Aobinta In
 
Frequency vs community impact
Frequency vs community impactFrequency vs community impact
Frequency vs community impactholdsteady
 
Characteristics of the kinase mutant TPK2 in bioreactors
Characteristics of the kinase mutant TPK2 in bioreactorsCharacteristics of the kinase mutant TPK2 in bioreactors
Characteristics of the kinase mutant TPK2 in bioreactors★ Beatriz Barrera Garmón
 
Transformer design
Transformer designTransformer design
Transformer designsulaim_qais
 
Ecology of grey squirrels
Ecology of grey squirrelsEcology of grey squirrels
Ecology of grey squirrelsShreya Ray
 
Toi dua em sang song
Toi dua em sang songToi dua em sang song
Toi dua em sang songhoangmeo60
 
Brian Bonnenfants Nevada Business Outlook 1 23 09
Brian Bonnenfants Nevada Business Outlook 1 23 09Brian Bonnenfants Nevada Business Outlook 1 23 09
Brian Bonnenfants Nevada Business Outlook 1 23 09aporrazzo
 
iGridd puzzles, Demo book
iGridd puzzles, Demo bookiGridd puzzles, Demo book
iGridd puzzles, Demo bookRastislav Rehak
 
Presenting objective and subjective uncertainty information for spatial syste...
Presenting objective and subjective uncertainty information for spatial syste...Presenting objective and subjective uncertainty information for spatial syste...
Presenting objective and subjective uncertainty information for spatial syste...University of Adelaide
 
Cache Creek Oklahoma Executive Summary
Cache Creek Oklahoma Executive SummaryCache Creek Oklahoma Executive Summary
Cache Creek Oklahoma Executive Summarystarr0167
 

Similar a Amth250 octave matlab some solutions (3) (20)

adc converter basics
adc converter basicsadc converter basics
adc converter basics
 
Machine learning projects with r
Machine learning projects with rMachine learning projects with r
Machine learning projects with r
 
Metrado de madera
Metrado de maderaMetrado de madera
Metrado de madera
 
Excel slide series - fractions introduction
Excel slide series -  fractions introductionExcel slide series -  fractions introduction
Excel slide series - fractions introduction
 
Las ม.2 ปีการศึกษา 2554
Las ม.2 ปีการศึกษา 2554Las ม.2 ปีการศึกษา 2554
Las ม.2 ปีการศึกษา 2554
 
Frequency vs community impact
Frequency vs community impactFrequency vs community impact
Frequency vs community impact
 
Characteristics of the kinase mutant TPK2 in bioreactors
Characteristics of the kinase mutant TPK2 in bioreactorsCharacteristics of the kinase mutant TPK2 in bioreactors
Characteristics of the kinase mutant TPK2 in bioreactors
 
DCT_TR802
DCT_TR802DCT_TR802
DCT_TR802
 
DCT_TR802
DCT_TR802DCT_TR802
DCT_TR802
 
DCT_TR802
DCT_TR802DCT_TR802
DCT_TR802
 
Education 3.0: Better Learning Through Technology
Education 3.0:  Better Learning Through TechnologyEducation 3.0:  Better Learning Through Technology
Education 3.0: Better Learning Through Technology
 
Transformer design
Transformer designTransformer design
Transformer design
 
Ecology of grey squirrels
Ecology of grey squirrelsEcology of grey squirrels
Ecology of grey squirrels
 
Toi dua em sang song
Toi dua em sang songToi dua em sang song
Toi dua em sang song
 
09 trial jpwp_s2
09 trial jpwp_s209 trial jpwp_s2
09 trial jpwp_s2
 
Brian Bonnenfants Nevada Business Outlook 1 23 09
Brian Bonnenfants Nevada Business Outlook 1 23 09Brian Bonnenfants Nevada Business Outlook 1 23 09
Brian Bonnenfants Nevada Business Outlook 1 23 09
 
鹿沢万座通信25号
鹿沢万座通信25号鹿沢万座通信25号
鹿沢万座通信25号
 
iGridd puzzles, Demo book
iGridd puzzles, Demo bookiGridd puzzles, Demo book
iGridd puzzles, Demo book
 
Presenting objective and subjective uncertainty information for spatial syste...
Presenting objective and subjective uncertainty information for spatial syste...Presenting objective and subjective uncertainty information for spatial syste...
Presenting objective and subjective uncertainty information for spatial syste...
 
Cache Creek Oklahoma Executive Summary
Cache Creek Oklahoma Executive SummaryCache Creek Oklahoma Executive Summary
Cache Creek Oklahoma Executive Summary
 

Más de asghar123456

assignment 1 properties of fluids-Fluid mechanics
assignment 1 properties of fluids-Fluid mechanicsassignment 1 properties of fluids-Fluid mechanics
assignment 1 properties of fluids-Fluid mechanicsasghar123456
 
Buckling test engt110
Buckling test engt110Buckling test engt110
Buckling test engt110asghar123456
 
Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)asghar123456
 

Más de asghar123456 (6)

assignment 1 properties of fluids-Fluid mechanics
assignment 1 properties of fluids-Fluid mechanicsassignment 1 properties of fluids-Fluid mechanics
assignment 1 properties of fluids-Fluid mechanics
 
Buckling test engt110
Buckling test engt110Buckling test engt110
Buckling test engt110
 
Assignment6
Assignment6Assignment6
Assignment6
 
Assignment5
Assignment5Assignment5
Assignment5
 
Assignment4
Assignment4Assignment4
Assignment4
 
Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)
 

Último

Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and stepobaje godwin sunday
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?TechSoup
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17Celine George
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.raviapr7
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxKatherine Villaluna
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesMohammad Hassany
 
How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17Celine George
 
The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsEugene Lysak
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxMYDA ANGELICA SUAN
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxraviapr7
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17Celine George
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxDr. Santhosh Kumar. N
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 

Último (20)

Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and step
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17
 
Finals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quizFinals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quiz
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptx
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming Classes
 
How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17
 
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdfPersonal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George Wells
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptx
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptx
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptx
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 

Amth250 octave matlab some solutions (3)

  • 1. AMTH250 Assignment 4 Due date: 27th August 2012 Solutions August 10, 2012 Question 1 The following data are related to the life expectation of citizens of two countries: 1975 1980 1985 1990 Tanab 72.8 74.2 75.2 76.4 Sarac 70.2 70.2 70.3 71.2 1. Use the interpolating polynomial of degree three to estimate the life ex- pectation in 1977, 1983, and 1988. 2. Repeat the computations using now the cubic spline interpolation. 3. Compare the above two results. octave:1> year=[1975 1980 1985 1990]; octave:2> tanab=[72.8 74.2 75.2 76.4]; octave:3> sarac=[70.2 70.2 70.3 71.2]; octave:4> ctanab=polyfit(year, tanab,3); octave:5> csarac=polyfit(year, sarac,3); octave:6> esttanab=polyval(ctanab, [1977 1983 1988]) esttanab = 73.446 74.810 75.858 octave:7> estsarac=polyval(csarac, [1977 1983 1988]) estsarac = 70.233 70.203 70.699 The estimated values in 1977, 1983 and 1988 are 73.446 74.810 75.858 for Tanab, and 70.233 70.203 70.699 for Sarac. 1
  • 2. Question 2 This is an interpolation problem. It solved by constructing the basis matrix and solving a linear system. octave:> x = [-2 -1 0 1 2]’; octave:> y = [125.948 7.673 -4 -14.493 -103.429]’; octave:> aa = [exp(-2*x) exp(-x) ones(5,1) exp(x) exp(2*x)]; octave:> coeffs = aay coeffs = 3.0000 -4.9998 -1.0004 1.0003 -2.0000 Thus the interpolating function is y ≈ 3e−2x − 5e−x − 1 + ex − 2e2x . Question 3 First we compute the interpolating functions: octave:> x = [0 0.01 0.04 0.09 0.16 0.25]’; octave:> y = [0 0.1 0.2 0.3 0.4 0.5]’; octave:> p = polyfit(x, y, 5); octave:> cs = interp1(x, y, ’spline’, ’pp’); octave:> pc = interp1(x, y, ’pchip’, ’pp’); Plotting the errors, i.e. the difference between the interpolating function √ and x we see that the pchip cubic is the most accurate over most domain. Restricting attention to the interval [0, 0.01] shows that they are all about equally inaccurate over that range. The reason for this is that the derivative √ of x is infinite at x = 0 making approximation by a function with a finite derivative at x = 0 difficult near x = 0. 2
  • 3. Polynomial Cubic Spline 0.03 0.03 0.02 0.02 0.01 0.01 0 0 -0.01 -0.01 -0.02 -0.02 -0.03 -0.03 0 0.05 0.1 0.15 0.2 0.25 0 0.05 0.1 0.15 0.2 0.25 Pchip Cubic 0.03 0.02 0.01 0 -0.01 -0.02 -0.03 0 0.05 0.1 0.15 0.2 0.25 Figure 1: Errors in interpolating functions. Polynomial Cubic Spline 0 0 -0.005 -0.005 -0.01 -0.01 -0.015 -0.015 -0.02 -0.02 -0.025 -0.025 0 0.002 0.004 0.006 0.008 0.01 0 0.002 0.004 0.006 0.008 0.01 Pchip Cubic 0 -0.005 -0.01 -0.015 -0.02 -0.025 0 0.002 0.004 0.006 0.008 0.01 Figure 2: Errors in interpolating functions in [0, 0.01]. 3
  • 4. Question 4 Cubic Spline 1st Derivative 12 3 10 2 8 1 6 0 4 -1 2 0 -2 1 2 3 4 5 6 7 1 2 3 4 5 6 7 2nd Derivative 3rd Derivative 8 8 6 6 4 4 2 2 0 0 -2 -2 -4 -4 -6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 Figure 3: Cubic spline and its derivatives. Pchip Cubic 1st Derivative 12 3 10 2.5 8 2 6 1.5 4 1 2 0.5 0 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 2nd Derivative 3rd Derivative 10 5 5 0 0 -5 -5 -10 -10 -15 1 2 3 4 5 6 7 1 2 3 4 5 6 7 Figure 4: Pchip cubic and its derivatives. 4
  • 5. From the graphs we see the defining conditions for a cubic spline are satisfied: 1. From the first plot the function interpolates the data. 2. From the second and third plots the function has continuous first and second derivatives. 3. From the fourth plot the function has constant third derivative on each subinterval. It follows that the function is a cubic polynomial on each subinterval. 4. The ‘not-a-knot’ condition shows up in the third derivative is the same on the first and second subintervals and on the second last and last subinter- vals. The defining conditions for a pchip cubic are also satisfied: 1. From the first plot the function interpolates the data. 2. From the second plot the function has continuous first derivative. The third plot shows that the second derivative is discontinuous. 3. From the fourth plot the function has constant third derivative on each subinterval. It follows that the function is a cubic polynomial on each subinterval. 4. In this example the data is monotonic, a property shared by the pchip cubic. This implies that the derivative of the pchip cubic does not change sign. The second plot shows that derivative is everywhere positive. Question 5 Write the equations in matrix form and solve the least squares problem with the backslash operator. octave:> A = [1 0 0 0 >0 1 0 0 >0 0 1 0 >0 0 0 1 >1 -1 0 0 >1 0 -1 0 >1 0 0 -1 >0 1 -1 0 >0 1 0 -1 >0 0 1 -1]; octave:> y = [2.95 1.74 -1.45 1.32 1.23 4.45 1.61 3.21 0.45 -2.75]’; octave:> x = Ay x = 2.9600 1.7460 -1.4600 1.3140 These values are within ±0.01 of the direct measurements. 5
  • 6. Question 6 Here is a script to compute and plot the fitted functions: x = 1:10; y = [27.7 39.3 38.4 57.6 46.3 54.8 108.5 137.6 194.1 281.2]; lx =log(x); ly =log(y); p = polyfit(x, y, 2); ce = polyfit(x, ly, 1); ae = exp(ce(2)); ke = ce(1); fe = @(x) ae*exp(ke*x); cp = polyfit(lx, ly, 1); ap = exp(cp(2)); kp = cp(1); fp = @(x) ap*x.^kp; clf() xx = linspace(1, 10, 201); plot(x,y,’or’) hold on plot(xx, polyval(p,xx)) plot(xx, fe(xx),’k’) plot(xx, fp(xx), ’g’) hold off 300 Quadratic Exponential Function Power Function 250 200 150 100 50 0 0 2 4 6 8 10 From this we see that the power function gives a poor fit, but visually there is little to chose between the quadratic polynomial and the exponential function. 6
  • 7. Part of the reason the power function y = axp gives such a poor fit is that when p > 0 the graph of the function must pass through the origin. Plotting the residuals res1 = y - polyval(p,x); res2 = y - fe(x); res3 = y - fp(x); Shows that the quadratic polynomial has the smallest residuals. This is con- firmed by the norms octave:> norm(res1) ans = 43.364 octave:> norm(res2) ans = 70.894 octave:> norm(res3) ans = 151.69 150 Quadratic Exponential Function Power Function 100 50 0 -50 0 2 4 6 8 10 Figure 5: Residuals of fitted functions. A semilog plot of the data indicates that an exponential function function may give a good description of the data. When working with the semilog data, the appropriate residuals are the differences log yi − log f (xi ) lres1 = ly - log(polyval(p,x)); lres2 = ly - log(fe(x)); lres3 = ly - log(fp(x)); Using the semilog scale that the exponential function has the smallest resid- uals. This is confirmed by the norms 7
  • 8. octave:> norm(lres1) ans = 0.87342 octave:> norm(lres2) ans = 0.66707 octave:> norm(lres3) ans = 1.1785 Fitted Functions Semilog Residuals 6 0.8 Quadratic Quadratic Exponential Function Exponential Function Power Function Power Function 0.6 5.5 0.4 5 0.2 4.5 0 4 -0.2 3.5 -0.4 3 -0.6 2.5 -0.8 0 2 4 6 8 10 0 2 4 6 8 10 Figure 6: Semilog plot of fitted functions and semilog residuals. A log-log plot of the data indicates that a power function would not be expected to give a good fit to the data. 6 5.5 5 4.5 4 3.5 3 0 0.5 1 1.5 2 2.5 Figure 7: Log-log plot of the data 8
  • 9. In summary 1. The power function does not give a good representation of the data. 2. The quadratic polynomial and exponential function give reasonable rep- resentations of the data. 3. Examining the residuals would indicate that the quadratic gives the best representation. 4. A semilog plot indicates that an exponential function may give a good representation of the data. Another reason for preferring the exponential is that it is monotonic and we may believe from examining the data that the underlying trend is monotonic. The exponential function is monotonic, the quadratic polynomial is not. 9