Evaluation of integral2. Error
3 ビュー (過去 30 日間)
古いコメントを表示
DIMITRIS GEORGIADIS
2021 年 2 月 20 日
コメント済み: DIMITRIS GEORGIADIS
2021 年 2 月 23 日
Using the following code I get a matrix dimension error. I suspect something goes wrong when I integrate out z from func_3. Could anyone help on that?
clear all; clc; close all;
% Define functions:
func_1 = @(x) (1/(0.1*sqrt(2*pi))).*exp(-0.5.*((x - 1)./0.1).^2);
func_2 = @(y) (1/(0.01*sqrt(2*pi))).*exp(-0.5.*((y - 0.1)./0.01).^2);
func_12 = @(x, y) func_1(x).*func_2(y);
% Visualization:
fcontour(func_12,[0.8 1.2 0.05 0.15])
% Define new function:
c = 1.05;
sigma_e = 0.05;
func_3 = @(x, y, z) (1./y).*exp(-0.5.*((z - x)./y).^2).*...
exp(-0.5.*((c - z)./sigma_e).^2);
% Intergate out z:
l_bound = -Inf;
u_bound = Inf;
func_4 = @(x, y) integral(@(z) func_3(x, y, z), l_bound, u_bound);
% Get the new function:
func_5 = @(x, y) func_4(x, y).*func_12(x, y);
% Compute the integral:
q = integral2(func_5, -Inf, Inf, 0, Inf);
w = 1/q;
0 件のコメント
採用された回答
Shashank Gupta
2021 年 2 月 23 日
Hi Dimitris,
It does look like problem is in integration of func_3 and looking at the error I feel like some kind of matrix or vector is involved in the calculation. My first attempt to solve this issue is to enable "ArrayValued" flag in integral function. This will make sure the whenever the matrix or vector calculation involved will smoothly run. I am attaching the changes below. It should work.
func_4 = @(x, y) integral(@(z) func_3(x, y, z), l_bound, u_bound,"ArrayValued",1);
I hope this resolves the issue.
Cheers
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!