{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter16

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

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

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,' ‐‐ ')

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

View Full Document
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
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)

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}