{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter16 - Problem 16.11 Runge's function is written as f...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Problem 16.11 Runge’s function is written as 2 1 ( ) 1 25 f x x Generate five equidistant points in the interval [ 1, 1] evaluate the function there and fit it using various options. First the data: >> x=linspace( 1,1,5) x = 1.0000 0.5000 0 0.5000 1.0000 >> [email protected](x) 1./(1+25*x.^2) runge = @(x)1./(1+25*x.^2) >> y=runge(x) y = 0.0385 0.1379 1.0000 0.1379 0.0385 Let us first use the crudest interpolation, which is to use the value of the nearest point >> xx=linspace( 1,1); >> yy=runge(xx); >> yexact=runge(xx); >> yy=interp1(x,y,xx,'nearest'); >> plot(x,y,'o',xx,yy,xx,yexact,' ‐‐ ')
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Next we will do linear interpolation, which is also linear spline, and the default method of interp1 >> ylin=interp1(x,y,xx); >> plot(x,y,'o',xx,ylin,xx,yexact,' ‐‐ ') -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Background image of page 2
Next we will fit it with a cubic spline. We can do that by choosing ‘spline’ in the method in interp1, or with the spline function (which gives additional flexibility on end conditions)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 6
Background image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}