How to make curve fit equation for 2 variables?

조회 수: 17 (최근 30일)
Muhammad Raza
Muhammad Raza 2014년 3월 21일
댓글: Muhammad Raza 2014년 3월 26일
Hello,
I have got a function with respect to 2 different variables. I want to make an equation of that function with respect to both the variables (for example: f(x1,x2) = ax1.x2^2 + bx1 +cx1^2). Is there anyone have an idea how i can make it? please let me know..
I am looking forward
Cheers Raza

채택된 답변

Star Strider
Star Strider 2014년 3월 21일
편집: Star Strider 2014년 3월 21일
I went into some detail in my answer 2D data fitting - Surface. (It’s easier to hyperlink to it than to repeat it here.)
To use your equation in a regression model, this will work:
f = @(B,XY) B(1).*XY(:,:,1).*XY(:,:,2).^2 + B(2).*XY(:,:,1) + B(3).*XY(:,:,1).^2;
To see what it produces with arbitrary parameters and data:
[X Y] = meshgrid(0:10, 0:10);
XY(:,:,1) = X;
XY(:,:,2) = Y;
B = [3; 5; 7];
figure(1)
mesh(X, Y, f(B,XY))
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
It creates a surface.
  댓글 수: 11
Star Strider
Star Strider 2014년 3월 26일
편집: Star Strider 2014년 3월 26일
If you’re simply looking to fit your data to a polynomial surface rather than fit it to a model, I suggest using polyfitn that Image Analyst refers to in his answer.
Muhammad Raza
Muhammad Raza 2014년 3월 26일
Thank you so much sir .. I got what I was looking for. Your help regarding curve fitting is greatly appreciated :)
Cheers Raza

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 3월 25일
I'll also put in a plug for John D'Errico's polyfitn http://www.mathworks.com/matlabcentral/fileexchange/34765-polyfitn which I use to create a 2D polynomial fit to a surface, for example to create a smooth background image from a noisy, actual, image snapped from a camera.
Attached is a demo that uses it on a standard MATLAB demo image.

카테고리

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