繁体   English   中英

在Matlab中绘制隐式函数

[英]Plotting an implicit function in Matlab

我有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)}

我想根据同一绘图上$n$不同值,将$y=h(x,n)$用作$x$的函数。 我怎样才能做到这一点。 如果有帮助, $f(x,t,w,n)$具有以下形式

f(x,t,w,n)=\exp{-\frac{x^2+tw+wx}{n}}+\exp{-\frac{t^2+tx^2-2tx}{2n}}

我认为这可能满足您的要求。 我将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)]...
     }...
 )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM