필터 지우기
필터 지우기

Fitting a Surface to a Function of Two Independent Variables

조회 수: 6 (최근 30일)
Gaofeng Zhang
Gaofeng Zhang 2024년 2월 21일
답변: Steven Lord 2024년 2월 21일
Now I have two independent variables, x and y, and one dependent variable z, but I do not know the functional relationship between them. How can I fit the functional relationship between these two independent variables x, y, and the dependent variable z? For example, z = f(x, y), and I do not know the form of f.
  댓글 수: 1
KSSV
KSSV 2024년 2월 21일
Do you have the values of x, y and z? If so give the values. HAve a look in the function fit

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2024년 2월 21일
Let me ask you a simpler question. Here are two variables. What is the functional relationship between them? If y = f(x) what is f?
x = [1 2 3 4 5 6];
y = [0 0 0 0 0 0];
Constant "curve"
I'm guessing you'd say that f(x) = 0 is the relationship. It goes through all the points, right?
f1 = @(x) zeros(size(x));
xfine = 1:0.125:6;
figure
plot(x, y, 'o', xfine, f1(xfine), 'x-')
But you're incorrect, that's not the curve I had in mind.
Polynomial
Your next guess might be that the true form of f(x) is a polynomial whose roots are the values in x.
p = poly(x)
p = 1x7
1 -21 175 -735 1624 -1764 720
f2 = @(x) polyval(p, x);
figure
plot(x, y, 'o', xfine, f2(xfine), 'x-')
You'd be incorrect again, still not what I had in mind.
Sine curve
How about a sine curve as the curve?
f3 = @(x) sinpi(x);
figure
plot(x, y, 'o', xfine, f3(xfine), 'x-')
Sorry, but no.
"The" curve is not unique
As you can probably guess from the fact that I've bolded the word the when I refer to the curve, and from the fact that I've shown three curves (admittedly the first one is trivial) that pass through those six points, the curve that passes through those points is not unique. You can have an unbounded number of different curves that pass through those points; multiply any curve by either the polynomial or the sinpi curve and it'll go through those points. [Assuming it's defined at those points.]
f4 = @(x) f2(x).*(sin(x)+cos(x).*exp(x)); % polynomial times other stuff
figure
plot(x, y, 'o', xfine, f4(xfine), 'x-')
Without more information, how can you tell whether f1, f2, f3, f4, or some other curve I haven't shown is the correct curve to fit the data? You can't.
So what can you do?
There are tools in MATLAB and several other MathWorks products for doing curve fitting: see here and here for two documentation pages in MATLAB, or see the Curve Fitting Toolbox or the Statistics and Machine Learning Toolbox or the Optimization Toolbox .... But generally speaking they all require you to know something about the curve you're trying to fit.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by