numer:true;
fpprintprec:6;
ratprint:false;

s(x):=a*x+b;

eq:[s(x[i])=f[i],s(x[i+1])=f[i+1]];

we:solve(eq,[a,b]);

[a,b]:ev([a,b],we);

s(t):=''(a*t+b);

spl(x):=block(i:floor((x-p)/h),s(x));

p:1;
f(x):=x^2*sin(x/2);
h:1;
create_list([x[i]:p+h*i,f[i]:f(x[i])],i,0,8);

spl(2);

load(draw);

wxdraw2d(line_width=3,nticks=250,parametric(x,spl(x),x,1,8),color=green,nticks=250,line_type=solid,parametric(x,x^2*sin(x/2),x,1,8));

plot2d([spl(x),x^2*sin(x/2)],[x,1,9],[y,-80,20]);