How to predict the function in two variables?

18 visualizaciones (últimos 30 días)
Susmit Kumar Mishra
Susmit Kumar Mishra el 6 de Jun. de 2020
Editada: John D'Errico el 8 de Jun. de 2020
I want to generate a function in two independent variables f (t, X) . I have the data of f at some particular t and X.(Like @t=0.33 , t=0.67,t=1 I have the values for all x, similarly at x=0.2,0.4,0.6,0.8 I have f for all t). To make it simple i have the f data in a matrix with rows as t and columns as x .
So with my limited data i want to predict the value of f at other points by some methods.
Further this plot is f vs x at cont t, similarly I have data for f vs t at const x. So I want to combine all these data to be able to get an approximate function f(x,t).
As some of you wanted to have a look at the data I am attaching the data along with this.
I have a gut feeling this is a trivial question and there exist no unique answer and i had a look at documentation for regression and optimisation but those seem to be too complex for me to understand.
  3 comentarios
Susmit Kumar Mishra
Susmit Kumar Mishra el 7 de Jun. de 2020
Editada: Susmit Kumar Mishra el 7 de Jun. de 2020
yes, exactly Andrew further this plot is f vs x at cont t, similarly i have plots for f vs t at const x. So i want to combine all these data to be able to get an approximate function f(x,t).
John D'Errico
John D'Errico el 8 de Jun. de 2020
Editada: John D'Errico el 8 de Jun. de 2020
As I show in my second answer, your gut feeling is wrong, because your data is not self consistent. There can be no trivial solution. Even if you look for a more sophisticated solution, no solution will exist until you fix your data.

Iniciar sesión para comentar.

Respuesta aceptada

John D'Errico
John D'Errico el 8 de Jun. de 2020
Editada: John D'Errico el 8 de Jun. de 2020
I've answered this question separately from my other answer, since it is now clear that you have essentially data that is scattered in the (x,t) plne. You have traces of some function, where one variable is held constant, while the other variable varies. You have done that three times by fixing t at constant levels. Then you did it twice more, fixing x at two levels, while varying t. That is clear from the data set you have posted in the xls file on a comment.
The result however is you effectively have scattered data. This leaves you with two options, since you have not told us of even a hint as to some model that would describe the physical process under study. You might try to use either use a tool like scatteredInterpolant, or you can attempt to fit a polynomial model. Before you do any of that however, you need to PLOT YOUR DATA. And while you have done two plots that give a fair amount of information, the plot of real importance is not there yet.
First is to recognize that your data really is scattered data.
I've attached a file named xtf.mat to this answer It contains ONE array of data, taken from the ,xls file you posted.
load xtfc
x = xtfc(:,1);
t = xtfc(:,2);
f = xtfc(:,3);
curve = xtfc(:,4);
The 4th column of that array is an index from 1 to 5, indicating which of the 5 curve traces the data came from.
This plot shows what you have created, as the data lives in the (x,t) plane.
plot(x,t,'o')
xlabel x
ylabel t
At every one of those points, you have some number f(x,t) associated with that point. Now you are asking how to find a function that represents the valuae of that function at any general value of x and t.
As I said, your data is scattered. It does not even completely fill the square region containing your data, if you look carefully at the numbers. There are the corners of that plot where no information was generated, thus in the lower left and right corners when x is near 0 or 1, and t is small, there was no information provided.
As well, along the right edge of the tegion, while it appears as if x goes all the way to 1, it does not. You gernally sopped just short of 1 in x along each of those curves.
So not only are there massive holes in your data and unfilled corners, even along the edges of the region there are also problems that would require some degree of extrapolation.
And, finally, there appears to be a singularity in this unknown relationship. That is, look carefully at the plots you posted in your question itself.
For all values of t, when x approaches zero, f(0,t) would seem to be zero. However then consider the second set of curves. They indicate that for all values of x, when t is zero, then f(x,0) takes on the value 1.
A singularity would then seem to happen in the bottom left corner of that square region of the (x,t) plane. What happens when both x and t approach 0? No information is provided that can give any inkling of the behavior of that function of x and t. Sadly, this essentially precludes using any sort of a polynomial model to predict the relationship in your data. Polynomials do not handle singularities well. In fact, no polynomial model with a finite number of terms can predict a singularity.
Sadly, there is another serious problem in your data, far worse than the problem of a singularity. While those curves you have drawn are fairly nice and regular, they are inconsistent with each other.
plot3(x,t,f,'o')
xlabel x
ylabel t
view(136,25)
I've plotted the data here in three dimensions. You now need to look at the curve with x fised at 0.1875. See that it appears to float above the other data? You may need to rotate the figure around to see this. The curve where x was fixed at 0.5 seems to intersect the others nicely.
To see that, I'll interpolate these curves.
c1 = curve == 1; % x is fixed at 0.1875
c2 = curve == 2; % x is fixed at 0.5
c3 = curve == 3; % t is fixed at 0.333335
c4 = curve == 4; % t is fixed at 0.666667
c5 = curve == 5; % t is fixed at 1
Now, from curves 3, 4 and 5, what is the approximate value of f(0.5,t) from each curve when x=0.5?
interp1(x(c3),f(c3),.5) % t = 1/3
interp1(x(c4),f(c4),.5) % t = 2/3
interp1(x(c5),f(c5),.5) % t = 1
ans =
0.54499
ans =
0.30944
ans =
0.034048
Now, I'll find those same points off of the curve trace where x was fixed at 0.5.
interp1(t(c2),f(c2),1/3)
interp1(t(c2),f(c2),2/3)
interp1(t(c2),f(c2),0.998)
ans =
0.53043
ans =
0.30738
ans =
0.034
These predictions are nearly dead on. Those traces of your function overlay very nicely. We only have three points to compare, but what we have suggests these traces are consistent with each other.
Now, do exactly the same thing, when x = 0.1875.
interp1(x(c3),f(c3),0.1875) % t = 1/3
interp1(x(c4),f(c4),0.1875) % t = 2/3
interp1(x(c5),f(c5),0.1875) % t = 1
ans =
0.45328
ans =
0.2302
ans =
0.019213
I'll find those same points off of the curve trace where x was fixed at 0.1875.
interp1(t(c1),f(c1),1/3)
interp1(t(c1),f(c1),2/3)
interp1(t(c1),f(c1),0.991)
ans =
0.67971
ans =
0.41856
ans =
0.074
Do you see that these sets of predictions are wildly inconsistent?
The trace of your surface at x=0.1875 seems to float well above the other curves.
And that invalidates the use of any interpolation scheme, such as scatteredInterpolant.
Can you find a functional relationship that emulates the shape of this surface? Sadly, no. Nothing you will do will reconcile the problems in your data. Nothing will serve as an adequate model until you fix your data.
Certainly you can do nothing until you locate the problem with that trace along x=0.1875, since it is seriously inconsistent with the rest of your data. And even then, you will need to deal with the question of a singularity in this relationship. You need to provide more information about what happens when both x and t are small.

Más respuestas (1)

John D'Errico
John D'Errico el 6 de Jun. de 2020
Editada: John D'Errico el 6 de Jun. de 2020
Actually, probably not that. It appears there are three curves, each representing f(x), at ONE specific value of t. There are three curves shown, so three values for t.
So it is not the entire region of the plot that needs to be predicted. In fact, it appears the data seem to fill a rectangle in the (x,t) plane, though not very well in t. Really, the common way to plot this relation is as a surface f(x,t). The data is, as i say, sufficient for that, although it will be quite simple as a function of t.
Assuming I am correct, and I feel moderately confident in that claim, then a simple solution is just interp2. I lack your data, so I cannot really show how to do it. Just read the help and look at the examples for interp2. Alternatively, you could use griddedInterpolant, which will offer a function that you can simply evaluate at any point or set of points.
My question is if you feel you need a functional relationship you can write down on paper. I'm not sure why, but this often seems to be important to people. In that case, you really don't have sufficient information defining the total surface to build any model, especially since you don't seem to have offered any candidate models for the overall process.
A polynomial surface MIGHT be adequate here. That is, you MIGHT find that if a cubic polynomial is sufficient to model each of those simple functions of x at any specific level of t, then you could think of the coefficients of the cubic polynomials as at most quadratic functions of t. However, without your data to look at more seriously, this is difficult to know. If you want better help, then attach your data to a comment or to your question.
  1 comentario
Susmit Kumar Mishra
Susmit Kumar Mishra el 7 de Jun. de 2020
Editada: Susmit Kumar Mishra el 8 de Jun. de 2020
So I have improved my questions and provided one more plot for your understanding, also I am attaching the data corresponding to that.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by