surface fitting

I am using MATLAB 2007. I want to do surface fitting. Any help will be appreciated.
Thanks.

 採用された回答

Grzegorz Knor
Grzegorz Knor 2011 年 11 月 29 日

0 投票

See:
You can also write your own function e.g. by using the Optimization Toolbox.

その他の回答 (7 件)

smp
smp 2011 年 11 月 29 日

0 投票

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 日

0 投票

Add folder which contains this function to search path, and type:
help gridfit
smp
smp 2011 年 11 月 30 日

0 投票

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 日

0 投票

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 日

0 投票

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 日

0 投票

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 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

質問済み:

smp
2011 年 11 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by