The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
So now I'm trying to whip up matlab code that lets me make a clamped cubic spline with my given data points. I barely understand interpolating lagrange polynomials so if someone could whip up an explanation or point me in the right direction i'm already on wikipedia article for Spline interpolation so more help from there please.
I would like to put something clever and about me but I fear my company will find it
also my teacher said our best bet was to rewrite this code she gave us. But for some reason it doesn't work at all for me. In class she just fired up matlab ran this function and it spat out what she needed. but I can't get it to work. Could someone please maybe check this? i wish I had friends in my classes.
**********************************
function sp=duck(y)
Holy crap man -- my degree is Computer Science, and my last math class had currently-employed high school math teachers in it as students -- and I know nothing about cubic splines.
Still, have you looked at MathWorld and Wikipedia?
MEMBER OF THE PARANOIA GM GUILD
XBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )
I haven't looked over the function to see what it does, but as simple starting points:
1. Is the file name for your function also "duck"? I don't think Matlab likes it when the function name, as listed on the first line, doesn't match the file name.
2. Do you have the function file in the working directory?
3. In the off chance you're naming the function something other than "duck," try changing the function name to something different. I've used names before that I thought for sure weren't system functions, but found out differently after getting errors no matter what I did (except changing the name).
Posts
**********************************
function sp=duck(y)
x=[.9 1.3 1.9 2.1 2.6 3 3.9 4.4 4.7 5 6 7 8 9.2 10.5 11.3 11.6 12 12.6 13 13.3];
a=[1.3 1.5 1.85 2.1 2.6 2.7 2.4 2.15 2.05 2.1 2.25 2.3 2.25 1.95 1.4 .9 .7 .6 .5 .4 .25];
main=ones(21,1);
upper=zeros(20,1);
lower=zeros(20,1);
f=zeros(21,1);
for n=1:20
h(n)=x(n+1)-x(n);
if n<20 lower(n)=h(n); end
if n>1 upper(n)=h(n);
main(n)=2*(h(n)+h(n-1));
f(n)=(a(n+1)-a(n))/h(n)-(a(n)-a(n-1))/h(n-1); end
end
f=3*f;
A=diag(main)+diag(lower,-1)+diag(upper,1);
c=A\f;
for n=1:20
b(n)=(a(n+1)-a(n))/h(n)-h(n)*(2*c(n)+c(n+1))/3;
d(n)=(c(n+1)-c(n))/(3*h(n));
if y>=x(n) & y<=x(n+1) sp=polyval([d(n) c(n) b(n) a(n)], y-x(n)); end
end
**********************
Still, have you looked at MathWorld and Wikipedia?
http://mathworld.wolfram.com/CubicSpline.html
http://en.wikipedia.org/wiki/Cubic_spline
XBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK
QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )
1. Is the file name for your function also "duck"? I don't think Matlab likes it when the function name, as listed on the first line, doesn't match the file name.
2. Do you have the function file in the working directory?
3. In the off chance you're naming the function something other than "duck," try changing the function name to something different. I've used names before that I thought for sure weren't system functions, but found out differently after getting errors no matter what I did (except changing the name).
Just some things to try