Problem: Badly conditioned interpolation

7 views (last 30 days)
Daniele Tarli
Daniele Tarli on 22 Feb 2016
Edited: John D'Errico on 23 Feb 2016
Hi everybody!
Today I was trying to fit some data deriving from a simulation I did, I went on apps and I used curve fitting. What I need is a surface that can interpolate my data, the problem is that when I try to interpolate them matlab says:
"Equation badly conditioned. Remove repeated data points or try centering and scaling".
I have already tried to do this and I do not have any positive results, it keeps on repeat the same thing. I did the same type of interpolation some days ago and it perfectly worked, could someone please tell me in what I am wrong? These are the data I am using:
clear all
pres=[1.030
1.025
1.020
1.015
1.010
1.005
1.000
0.995
0.990
0.985
0.980
0.975
0.970
0.965
0.960];
temp=[306.20
303.20
300.20
297.20
294.20
291.20
288.20
285.20
282.20
279.20
276.20
273.20
270.20
267.20
264.20];
fc=[2.3150
2.3157
2.3170
2.3208
2.3219
2.3237
2.3285
2.3346
2.3404
2.3463
2.3540
2.3631
2.3760
2.3887
2.4038];
plot3(pres,temp,fc)
I wrote these data in the script to use them in the "curve fitting" app, what I am looking for is a function who can help me to express fc as a function of pres and temp and I have the problem I described before when I put: the fc on the "z" axis, "pres" and "temp" on x and y axes. Any suggestions? Thank you!

Answers (2)

John D'Errico
John D'Errico on 22 Feb 2016
Edited: John D'Errico on 23 Feb 2016
I know, you WANT to get some function that represents this curve. Sorry, but you can't have one, at least not in the completely general case. But sometimes you get lucky, and you can have something almost as good. In this case, you got lucky.
You have a set of points that represent some space curve, a path the lies in the 3-d space with axes: (pres,temp,fc). Maybe you might call it a 1-manifold, embedded in that R^3 space.
The problem is, there is insufficient information to generate a viable model for that function. DON'T bother with 2-d polynomial models. Even if you did build a polynomial model, it would be a highly dangerous thing here.
Another thing that would be WRONG to do is to try to use a 2-d scattered data interpolant here (as you apparently tried). Yes, it failed, because those tools will try to build a triangulation of the domain pres X temp. I would hope that would indeed fail.
One option is to use a tool like my interparc , that will allow you to interpolate a general path in any number of dimensions, generating as many points along that path as you wish. interparc is on the file exchange. However, it does NOT give you any simple function that can be written down.
Another option is to consider fc as being simply a function of pres, OR temp. Either of those variables progresses smoothly along that curve. So, you could simply plot fc versus pres. Use a spline to model that curve, or a simple cubic polynomial will suffice on this problem.
fc(pres) = 209.71 + -602.39*pres + 583.48*pres.^2 + -188.47*pres.^3
That additional variable (temp) is not necessary for any prediction, in fact the above polynomial model works quite nicely. We can get those coefficients simply as:
p3 = polyfit(pres,fc,3)
p3 =
-188.46991789119 583.477986094436 -602.392028565816 209.712804916545
plot(pres,polyval(p3,pres),'-r',pres,fc,'bo')
grid on
So you can think of temp as another variable that can be predicted from pres. But temp is NOT necessary to predict the value of fc.
In fact, if we look at the relationship between pres and temp, we see that temp can be VERY simply predicted as a function of the other.
plot(pres,temp,'o')
grid on
xlabel pres
ylabel temp
In fact, that relationship is virtually a perfectly linear one:
p1 = polyfit(pres,temp,1)
p1 =
600.000000000002 -311.800000000002
So we would have:
temp = 600*pres - 311.8
  1 Comment
Daniele Tarli
Daniele Tarli on 22 Feb 2016
Ok, so the problem is that I'm using regular intervals for pres and temp, right? And if I undestood really well, Interpac will help to create some scattered points between the others that I'm trying to plot, right?

Sign in to comment.


Walter Roberson
Walter Roberson on 22 Feb 2016
Your pres and temp are each measured at regular intervals, 0.005 apart for pres and 3.00 apart for temp. The most you can do with that is find a parametric function of one variable.
  1 Comment
Daniele Tarli
Daniele Tarli on 22 Feb 2016
Do you mean a parametric function of pres or temperature?

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!