surface fitting

조회 수: 12 (최근 30일)
smp
smp 2011년 11월 29일
I am using MATLAB 2007. I want to do surface fitting. Any help will be appreciated.
Thanks.

채택된 답변

Grzegorz Knor
Grzegorz Knor 2011년 11월 29일
See:
You can also write your own function e.g. by using the Optimization Toolbox.

추가 답변 (7개)

smp
smp 2011년 11월 29일
Thanks.
I have downloaded the files on my Desktop of my Linux machine. What to do next i.e. how to incorporate gridfit in MATLAB 2007?
smp

Grzegorz Knor
Grzegorz Knor 2011년 11월 29일
Add folder which contains this function to search path, and type:
help gridfit

smp
smp 2011년 11월 30일
I did as you said.
Then I used this command:
zgrid = gridfit(x,y,z,xi,yi)
where
x= experimental x co-ordinates
y= experimental y co-ordinates
z= experimental values for each pair (x,y)
and
xi = linspace(-0.8,0.8,50)
yi= linspace(-0.8,0.8,50)
But where and when I will provide my "model surface" to be fitted to experimental data (x,y,z(x,y))?
My model surface is z(x,y)= c*( 2*(x^2+y^2)-1 )
And more important for me : How to obtain fitted coefficient c?
Thanks & Regards,
smp

Grzegorz Knor
Grzegorz Knor 2011년 11월 30일
Gridfit produce only smooth surface that approximates your data.
If you want to calculate the coefficient c from your model look at the example:
[x y] = meshgrid(-1:.1:1);
c = sqrt(2);
z = c*( 2*(x.^2+y.^2)-1 );
z = z + randn(size(z))/5;
plot3(x,y,z,'r.')
f = @(c)norm(z-c*( 2*(x.^2+y.^2)-1));
c1 = fminsearch(f,1);
z1 = c1*( 2*(x.^2+y.^2)-1 );
hold on
surf(x,y,z1,'FaceColor','none')

smp
smp 2011년 11월 30일
I worked out your example in my machine. It worked well. But I have some problems when I tried to do similar thing to my data:
I did this:
[x,y]=meshgrid(-0.707107:0.141421:0.707107)
c=1.0
f = @(c)norm(z-c*(2*(x^2+y^2)-1))
where z is a vector of experimental values (which I had loaded earlier by command "load z.txt")
Then I gave this command:
c1=fminsearch(f,0.1)
Then I got this message:
??? Error using ==> minus
Matrix dimensions must agree.
Error in ==> @(c)norm(z-c*(2*(x^2+y^2)-1))
Error in ==> fminsearch at 205
fv(:,1) = funfcn(x,varargin{:});
So what's my mistake?
Thanks & Regards,
smp
  댓글 수: 1
Grzegorz Knor
Grzegorz Knor 2011년 11월 30일
If z is a vector, then x and y should be vectors too.
BTW: add dots to this line before ^:
f = @(c)norm(z-c*(2*(x.^2+y.^2)-1))

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


smp
smp 2011년 12월 1일
I started afresh:
>> load x.txt
>> load y.txt
>> load z.txt
Here x,y,z are vectors each containing 121 entries. Basically I have array of 11x11 x values, array of 11x11 y values, and corresponding array of 11x11 z values. But for some reason I want x,y,z in vector forms.
Then I gave these commands:
>> c=1.0
>> f = @(c)norm(z-c* (2*(x.^2+y.^2)-1 ) )
>> c1=fminsearch(f,0.1)
(why dots are needed for x & y in 'f' ?)
I got c1 = 1.4958
But when I changed c to 5, still I got c1=1.4958
Obviously this is wrong.
Thanks & Regards,
smp
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 12월 1일
See the reference material for mpower ("^") and power (".^") to see when to use one or the other.
Changing the initial value of c to 5 has no effect on the code. The anonymous function f does not use the existing value of c in any way. The anonymous function uses c as a "dummy argument". Nothing would change if you were to instead use
f = @(ThisC)norm(z-ThisC* (2*(x.^2+y.^2)-1 ) )
smp
smp 2011년 12월 1일
Ok. thanks. But then what is the way to find fitted coefficient c?
Regards,
smp

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


smp
smp 2011년 12월 1일
To Walter Roberson (regarding your comment): Ok. thanks. But then what is the way to find fitted coefficient c?
Regards, smp

카테고리

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