Make an double integral function

조회 수: 8(최근 30일)
pankaj singh 2021년 11월 25일
편집: VBBV 2021년 11월 25일
I want to make the double integration function (as per the formula shown in figure below) and then evaluate the integral for the given range of x and y. Please help me make the function. My code is something like this but gives error:
fun = @(x,y) 1/sqrt(2*pi).*exp(-x.^2/2).*exp(-1/2.*(y+(u_j-u_m)/sigma_sq)).^2);
q = integral2(fun,y,Inf,-Inf,inf);

댓글을 달려면 로그인하십시오.

채택된 답변

Bjorn Gustavsson 2021년 11월 25일
By putting the product inside the first pair of square brackets you've made the formula look a little bit confusing - since the only factors that depend on j and m_n are outside that parenthesized factor, but I'll give it a try...
The inner integral over x is just the error-function:
(erf(y/2^(1/2)) + 1)/2
This should give you a modified function, something like this:
fun = @(y) ((erf((2^(1/2)*y)/2) + 1))/2.*exp(-1/2*(y+(u_j-u_m)/s_n).^2);
Which for your desired values of u_j, u_m and s_n will integrate just fine from -inf to inf.
HTH

댓글을 달려면 로그인하십시오.

추가 답변(1개)

VBBV 2021년 11월 25일
편집: VBBV 2021년 11월 25일
u_j = 10.4;% select a value
u_m = 2.6; % give a value
sigma_sq = 1.1;% assume a value
syms x y
y = 0:0.1:10; % gvien range for y
% x = 5; % given value for x
fun1 = @(x) 1/sqrt(2*pi).*exp(-x.^2/2);
fun2 = @(y) exp(-1/2.*(y+(u_j-u_m)/sigma_sq).^2);
for i = 1:length(y)
L(i) = integral(fun1,-Inf,y(i));
K = integral(fun2,-Inf,Inf);
q(i) = L(i)*K;
end
%iwant
plot(q,'linewidth',1.5)
grid you can try this approach ,

댓글을 달려면 로그인하십시오.

R2021b

Community Treasure Hunt

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

Start Hunting!