x = -4:4;
y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0];
cs = spline(x,[0 y 0]);
xx = linspace(-4,4,101);
plot(x,y,'o',xx,ppval(cs,xx),'-');
coefficients = cs.coefs
fprintf('The equation for the different segments are:\n');
for k = 1 : size(coefficients, 1)
fprintf('y = %7.4f * x^3 + %7.4f * x^2 + %7.4f * x + %7.4f\n', coefficients(k,:));
end
coefficients =
0.20344440353461 -0.0534444035346097 0 0
-0.0903332106038293 0.55688880706922 0.50344440353461 0.15
-0.392111561119293 0.285889175257731 1.34622238586156 1.12
0.148779455081001 -0.890445508100147 0.741666053019146 2.36
0.136993740795287 -0.444107142857143 -0.592886597938144 2.36
0.13324558173785 -0.0331259204712812 -1.07011966126657 1.46
-0.0599760677466861 0.366610824742268 -0.736634756995581 0.49
-0.0633413107511046 0.186682621502209 -0.183341310751105 0.06
The equation for the different segments are:
y = 0.2034 * x^3 + -0.0534 * x^2 + 0.0000 * x + 0.0000
y = -0.0903 * x^3 + 0.5569 * x^2 + 0.5034 * x + 0.1500
y = -0.3921 * x^3 + 0.2859 * x^2 + 1.3462 * x + 1.1200
y = 0.1488 * x^3 + -0.8904 * x^2 + 0.7417 * x + 2.3600
y = 0.1370 * x^3 + -0.4441 * x^2 + -0.5929 * x + 2.3600
y = 0.1332 * x^3 + -0.0331 * x^2 + -1.0701 * x + 1.4600
y = -0.0600 * x^3 + 0.3666 * x^2 + -0.7366 * x + 0.4900
y = -0.0633 * x^3 + 0.1867 * x^2 + -0.1833 * x + 0.0600