[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What did I do wrong with this funtion? - Implementing msplines and
From: |
Jaroslav Hajek |
Subject: |
Re: What did I do wrong with this funtion? - Implementing msplines and isplines in Octave |
Date: |
Wed, 16 Sep 2009 11:26:43 +0200 |
On Wed, Sep 16, 2009 at 10:10 AM, Corrado <address@hidden> wrote:
> Dear friends,
>
> I am trying to implement in Octave the two spline families as in the
> documentation here below attached. I am a newbie to Octave, and this is my
> first function.
>
> I built the function:
>
> function retspline = mspline (i,x,k,t)
> # i is the spline index in the family
> # x is the variable
> # t is the vector of knots, t(h) is the h-th knot
> # k is the Mspline degree
>
> I=i
>
> if(k==1)
>
> if(x<t(i+1) & x>=t(i))
> td=t(i+1)-t(i)
> M=1/td
> else
> M=0
> endif
>
> else
>
> kk=(k-1)
>
> if (x>=t(i) & x<t(i+k))
> M=k*((x-t(i))*mspline(i=I,x=x,k=kk,t=t)+(t(i+k)-
> x)*mspline(i=(I+1),x=x,k=kk,t=t))/((k-1)*(t(i+k)-t(i)))
> elseif (x<t(i) | x>=t(i+k))
> M=0
> endif
>
> endif
>
> retspline=M
>
> endfunction
>
> but for some reason it does not work ....
>
> I add that I am a newbie with Octave, please do not shut me.
>
> What did I do wrong?
>
> Best,
> --
> Corrado Topi
>
You're probably misinterpreting the expression
`mspline(i=I,x=x,k=kk,t=t)' (did you program in Python or Fortran?)
In Octave, there is no passing parameters by name, and the expression
is interpreted like in C, so that it means:
i=I,x=x,k=kk,t=t,mspline(i,x,k,t)
which probably spoils your script by overwriting variables. I didn't
check for other problems.
Note that even if you succeed, this will be a very inefficient
implementation in Octave, but probably good enough to start
programming.
hth
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz