How to correctly solve cubic spline interpolation?

2 ビュー (過去 30 日間)
adi kul
adi kul 2016 年 5 月 19 日
編集済み: John D'Errico 2016 年 5 月 20 日
Hello All, I need help in cubic spline into matlab.
I am trying this:
a(i,j,k)=interp1(x(j),m-1,x1,x2);
where x(j) is a 1x20 matrix, m=20, n=30, x1=zeros(m), x2=zeros(n)
For the above command I am getting
Wrong number of input arguments
this error. Can anyone help me to correctly model this?
  2 件のコメント
Stephen23
Stephen23 2016 年 5 月 19 日
@adi kul: please edit your question and tell us what the dependent and independent variable are, and which points you want to evaluate the function at.
adi kul
adi kul 2016 年 5 月 20 日
Actually I am porting a fortran77 code into matlab where fortran code uses this:
call dcsint(m,xy,xz,x1,x2)
do 10 k = 1,m
a(i,j,k)= = dcsval(x(j),m-1,x1,x2))
As dcsint is the cubic spline function, I wanted to have the same in matlab.

サインインしてコメントする。

回答 (1 件)

John D'Errico
John D'Errico 2016 年 5 月 19 日
編集済み: John D'Errico 2016 年 5 月 19 日
To "model it" makes no sense when you talk about an existing piece of software, that is well documented. So I'm not sure what you intend there.
If your goal is to use interp1 to do some sort of interpolation using two independent variables, again, this makes no sense, since interp1 is not designed to take more than one independent variable as an input. Interp1 is NOT a two-dimensional tool. The 1 at the end of the name is a hint that interp1 is a 1 (ONE) dimensional software.
So if you need a tool that can interpolate as a function of two input variables, use a tool like interp2 or griddata or scatterInterpolant.
If for some reason you wish to write something like one of those tools, and want us to write it for you, then I'm sorry, but this site does not do your work for you. Anyway, that answer would take far too long a time to write, essentially a book on the topic. You would need to do some reading about one of the many ways to do interpolation in more than one dimension, and then start writing code.
Anyway, it is rarely a good idea to re-write existing high quality software, written by a professional in that art of mathematics.
If your wish is something completely different, then you need to explain what your needs are, and do so far more clearly.
  4 件のコメント
adi kul
adi kul 2016 年 5 月 20 日
Thank you John for your time on answering this question. Actually I am porting a fortran77 code into matlab where fortran code uses this:
call dcsint(m,xy,xz,x1,x2)
do 10 k = 1,m
a(i,j,k)= = dcsval(x(j),m-1,x1,x2))
As dcsint is the cubic spline function, I wanted to have the same in matlab.
John D'Errico
John D'Errico 2016 年 5 月 20 日
編集済み: John D'Errico 2016 年 5 月 20 日
It would be easier if I did not have to ask so many questions, instead you could be more proactive with such clearly necessary information. Is this perhaps DCSINT and DCSVAL that you are using, from the IMSL library? OR is this DCSINT from NETLIB/TOMS that you are using?
If the IMSL routine, DCSINT creates a spline using the not-a-knot end conditions, and DCSVAL evaluates that spline?
Interestingly, finding documentation for any of these codes online seems surprisingly difficult. All of the links seem to be broken. Perhaps that is a signal that IMSL is itself no longer supported.
Anyway, the first problem is that you are trying to write MATLAB as if it was fortran. In fortran, you pass in the entire argument list, both input and return arguments on the right. In MATLAB, the return arguments are on the left. So, it appears that x2 in the call to DCSVAL should be the return argument.
I'll need to find documentation for DCSINT and DCSVAL to know.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by