Matlab:二维投影的三维函数。

时间:2022-09-10 18:53:50

I have a function f(x,y)= Exp(-x^2-y^-2)(x^2+y^2). I would like to look at the projection of this function onto the x-axis in MATLAB.

我有一个函数f(x,y)= Exp(- x ^ 2 y ^ 2)(x ^ 2 + y ^ 2)。我想看一下这个函数在MATLAB中的投影。

Any thoughts on the best way to do this?

有什么想法吗?

3 个解决方案

#1


3  

something like this:

是这样的:

xs = [];
ys = [];
zs = [];
for x = -10:0.1:10
    for y = -10:0.1:10
        xs = [xs x];
        ys = [ys y];
        z = f(x,y);
        zs = [zs z];
    end
end
figure; plot3(xs,ys,zs);  %plots the full function over both dimensions
figure; plot(xs,zs,'rx'); %plots the projection onto the x axis
figure; plot(ys,zs,'rx'); %plots the projection onto the y axis

that does it over the range -10 to 10 along both x and y but you can change that accordingly.

在x和y轴上的范围是-10到10,但是你可以相应地改变。

#2


3  

@Amro has a great solution, but you might also take a look at Scott Hirsch's awesome shadowplot from the MATLAB Central File Exchange. Check it out:

@Amro有一个很好的解决方案,但是您也可以从MATLAB的*文件交换中查看Scott Hirsch的可怕的阴影图。检查一下:

>> f = @(x,y) exp(-x.^2 -y.^(-2)).*(x.^2+y.^2);
>> [X,Y] = meshgrid(-10:0.5:10,-10:0.5:10);
>> surf(X,Y,f(X,Y))
>> xlim([-11,11])
>> ylim([-11,11])
>> shadowplot x
>> shadowplot y

Matlab:二维投影的三维函数。

#3


1  

You can manipulate the view to see the 2D-projection on the x-axis:

你可以利用视图来观察x轴上的二维投影:

f = @(x,y) exp(-x.^2 -y.^(-2)).*(x.^2+y.^2);
[X,Y] = meshgrid(-10:0.5:10,-10:0.5:10);
surf(X,Y,f(X,Y))
view(90,0), shading interp
xlabel X, ylabel Y, zlabel Z

Matlab:二维投影的三维函数。

#1


3  

something like this:

是这样的:

xs = [];
ys = [];
zs = [];
for x = -10:0.1:10
    for y = -10:0.1:10
        xs = [xs x];
        ys = [ys y];
        z = f(x,y);
        zs = [zs z];
    end
end
figure; plot3(xs,ys,zs);  %plots the full function over both dimensions
figure; plot(xs,zs,'rx'); %plots the projection onto the x axis
figure; plot(ys,zs,'rx'); %plots the projection onto the y axis

that does it over the range -10 to 10 along both x and y but you can change that accordingly.

在x和y轴上的范围是-10到10,但是你可以相应地改变。

#2


3  

@Amro has a great solution, but you might also take a look at Scott Hirsch's awesome shadowplot from the MATLAB Central File Exchange. Check it out:

@Amro有一个很好的解决方案,但是您也可以从MATLAB的*文件交换中查看Scott Hirsch的可怕的阴影图。检查一下:

>> f = @(x,y) exp(-x.^2 -y.^(-2)).*(x.^2+y.^2);
>> [X,Y] = meshgrid(-10:0.5:10,-10:0.5:10);
>> surf(X,Y,f(X,Y))
>> xlim([-11,11])
>> ylim([-11,11])
>> shadowplot x
>> shadowplot y

Matlab:二维投影的三维函数。

#3


1  

You can manipulate the view to see the 2D-projection on the x-axis:

你可以利用视图来观察x轴上的二维投影:

f = @(x,y) exp(-x.^2 -y.^(-2)).*(x.^2+y.^2);
[X,Y] = meshgrid(-10:0.5:10,-10:0.5:10);
surf(X,Y,f(X,Y))
view(90,0), shading interp
xlabel X, ylabel Y, zlabel Z

Matlab:二维投影的三维函数。