2-Two Variables Function corss-section

二元函数的分解理解

二元函数可以从两个变量的方向分解开来研究

固定一个变量, 改变另一个变量,得到一组一元函数

在下列函数图里:

  1. 第一列固定 y值(取一组离散值),改变 x值(连续变量)

  2. 第二列x,y 都是连续值,二元函数自身

  3. 第三列固定 x值(取一组离散值),改变 y值(连续变量)

这里的方法和概率概念的边缘概率(marginal probability)一样, 意思是给定一个条件(固定一个值), 改变另一个变量的取值. 二元分布的概率密度函数就是二元函数,只不过曲线下积分等于 1

Code
using GLMakie
xs = ys = -3:0.1:3
xs2 = ys2 = -2:1:2
len = length(xs)
f1(x, y) = x^2 - y^2
f2(x, y) = ^((x^2)  (y^2))
f3(x, y) = y^2
f4(x, y) = 2 + 2x - y
f5(x, y) = x + 2y + 3
f6(x, y) = x^2 + y^2
f7(x, y) = -x^2 - y^2
f8(x, y) = x^2 

func_arr = [f1,f2,f3,f4,f5,f6,f7,f8]
latexstr_arr=[L"f(x, y) = x^2 - y^2",L"f(x,y)=ℯ^{−x^2 −y^2}",L"f(x,y)=y^2",
L"f(x,y)=2 + 2x - y",L"f(x,y)=x + 2y + 3",L"f(x,y)=x^2 + y^2",L"f(x,y)=-(x^2+y^2)",L"f(x,y)=x^2"]

"""
 make_z(index::Int)
 根据函数索引返回 julia 函数表达式和
 函数 latex string
"""
function make_z(index::Int)
    return ( (x,y)->func_arr[index](x,y),latexstr_arr[index])
end
make_z
Code
function plot_func(func_z,latexstr)
    f = Figure(resolution=(1800, 1000))
    ax1 = Axis3(f[1, 1], title=L"fixed y", azimuth=0.3pi)
    ax2 = Axis3(f[1, 2], title=L"surface", azimuth=0.3pi)
    ax3 = Axis3(f[1, 3], title=L"fixed x", azimuth=0.3pi)
    ax4 = Axis(f[2, 1])
    ax5 = Axis(f[2, 3])
    ax6 = Axis3(f[2, 2], azimuth=0.3pi)
    Label(f[0, :], latexstr, fontsize=40)
    zs = [func_z(x, y) for x in xs, y in ys]
    surface!(ax2, xs, ys, zs, color=:lightblue)
    for y in ys2
        yspan = fill(y, len)
        lines!(ax1, xs, yspan, func_z.(xs, yspan), color=:black, lw=3)
        lines!(ax4, xs, func_z.(xs, y), color=:black, lw=3)
        lines!(ax6, xs, yspan, func_z.(xs, yspan), color=:black, lw=3)
    end
    for x in xs2
        xspan = fill(x, len)
        lines!(ax3, xspan, ys, func_z.(xspan, ys), color=:red, lw=3)
        lines!(ax5, ys, func_z.(x, ys), color=:red, lw=3)
        lines!(ax6, xspan, ys, func_z.(xspan, ys), color=:red, lw=3)

    end

    surface!(ax6, xs, ys, zs, color=:lightblue)


    return f
end
plot_func (generic function with 1 method)
Code
let 
make_z(1)|>d->plot_func(d[1],d[2]) 
end

Figure 1: 1

Figure 2: 3

Figure 3: 4

Figure 4: 5

Figure 5: 6

Figure 6: 7

Figure 7: 8

Figure 8: 9

Figure 9: 10