代码之家  ›  专栏  ›  技术社区  ›  per

在Matlab中绘制隐函数

  •  0
  • per  · 技术社区  · 7 年前

    我有一个由4个变量组成的函数 $f(x,t,w,n)$ ,函数 $g(x,n)$ 定义为

    g(x,n)=\int_a^b\int_c^d f(x,t,w,n) dt dw
    

    哪里 $a$, $b$, $c$, $d$ 是给定的常数,积分不能以闭合形式显式计算。然后 $h(x,n)$ 由给出

    h(x,n)=\ln\frac{g(x,n)}{g(-x,n)}
    

    我想耍花招 $y=h(x,n)$ 作为的函数 $x$ 对于不同的值 $n$ 在同一个地块上。我该怎么做。如果有帮助, 具有以下形式

    f(x,t,w,n)=\exp{-\frac{x^2+tw+wx}{n}}+\exp{-\frac{t^2+tx^2-2tx}{2n}}
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Sevenless    7 年前

    我想这可能正是你想要的。我指定f、g和h为匿名函数,并使用quad2d来估计二重积分的值。

    %% Input bounds
    a = 0;
    b = 1;
    c = 0;
    d = 2;
    
    %% Specify functions
    
    % vectorize function as a prerequisite to using in quad2d
    f = @(x,t,w,n) exp( -(x.^2 + t.*w + w.*x)./n) + exp(-(t.^2 + t.*x.^2 - 2.*t.*x)./(2.*n));
    
    % keeps x,n fixed in function call to f(...), varies a < t < b; c < w < d
    g = @(x,n) quad2d(@(t,w) f(x, t, w, n), a, b, c, d);
    
    % wrap functions into h
    h = @(x,n) log(g(x,n)/g(-x,n));
    
    %%
    
    figure();
    hold on % keep lines
    
    x_range = linspace(-1,1);
    
    for n = 1:5
        plotMe = zeros(1, length(x_range));
        for iter = 1:length(x_range)
            plotMe(iter) = h(x_range(iter), n);
        end
    
        lineHandle(n) = plot(x_range, plotMe);
    end
    
    
     legend(lineHandle, {
         ['N: ', num2str(1)],...
         ['N: ', num2str(2)],...
         ['N: ', num2str(3)],...
         ['N: ', num2str(4)],...
         ['N: ', num2str(5)]...
         }...
     )