How to correctly solve cubic spline interpolation?
Afficher commentaires plus anciens
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?
Réponses (1)
John D'Errico
le 19 Mai 2016
Modifié(e) : John D'Errico
le 19 Mai 2016
0 votes
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 commentaires
adi kul
le 19 Mai 2016
John D'Errico
le 19 Mai 2016
Modifié(e) : John D'Errico
le 19 Mai 2016
As I said, it still is not a properly formed question, since it is not consistent.
If you wish to use a ONE dimensional spline, then just use interp1, spline, pchip, etc, and do so properly. Those tools have help, and good help.
If you wish to use a higher dimensional spline, so a function of more than one input variable, then use one of the tools designed to solve that problems. I told you of several such options.
If you want to write your own code, Why do so when code exists already?
If you want to learn to write your own code for one of the above purposes, this question is arguably not on-topic on this site, as it would take far too much time to answer. Instead, you want to read a book, or take a course, as this will take some reading on your part.
Anyway, your question makes no sense, because it appears that you are calling interp1 with ONE independent variable (i.e., x(j)) but then apparently trying to pass in TWO independent variables (i.e., x1 and x2.)
Finally, your comment describes cubic interpolation, which arguably is a different thing from cubic SPLINE interpolation.
So what do you truly wish to do? Be clear about it. How many variables do you have? How many dimensions? Do you have one independent variable, or two variables? Are you trying to find/use the appropriate existing code? Are you trying to learn to write that code?
adi kul
le 20 Mai 2016
John D'Errico
le 20 Mai 2016
Modifié(e) : John D'Errico
le 20 Mai 2016
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.
Catégories
En savoir plus sur Interpolation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!