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;
Best Answer