How can I rectify this error? 'Invalid use of Operator.' 'Too many Output arguements'

1 view (last 30 days)
affineTransformGauss calculates the mean and covariance of y, the transformed variable, exactly when the function, f, is defined as y = f(x) = Ax + b, where A is a matrix, b is a vector of the same dimensions as y, and x is a Gaussian random variable.
%Input
% MU_X [n x 1] Expected value of x.
% SIGMA_X [n x n] Covariance of x.
% A [m x n] Linear transform matrix.
% B [m x 1] Constant part of the affine transformation.
% x
%Output
% MU_Y [m x 1] Expected value of y.
% SIGMA_Y [m x m] Covariance of y.
function [mu_y, Sigma_y] = affineGaussianTransform(mu_x, Sigma_x, A, b)
%Code here
x=horzcat(mu_x,Sigma_x);
C=A*x;
[mu_y, Sigma_y]= (C+b)
end
%Code to call your function
mu_x= [7;3];
Sigma_x= [0.2 0; 0 8];
A=[1 1; 1 -1];
b=0;
%Calculate y
[mu_y, Sigma_y]=affineGaussianTransform(mu_x, Sigma_x, A, b)
  5 Comments

Sign in to comment.

Answers (1)

VBBV
VBBV on 20 Mar 2023
%Input
% MU_X [n x 1] Expected value of x.
% SIGMA_X [n x n] Covariance of x.
% A [m x n] Linear transform matrix.
% B [m x 1] Constant part of the affine transformation.
% x
%Output
% MU_Y [m x 1] Expected value of y.
% SIGMA_Y [m x m] Covariance of y.
%Code to call your function
mu_x= [7;3];
Sigma_x= [0.2 0; 0 8];
A=[1 1; 1 -1];
b=zeros(length(A),1); % Make B as vector
%Calculate y
[mu_y, Sigma_y]=affineGaussianTransform(mu_x, Sigma_x, A, b)
mu_y = 3×1
3.3333 0.0667 2.6667
Sigma_y = 2×3
10.0000 0.2000 8.0000 4.0000 0.2000 -8.0000
function [mu_y, Sigma_y] = affineGaussianTransform(mu_x, Sigma_x, A, b)
%Code here
x=horzcat(mu_x,Sigma_x);
C=A.'*x+b; % calculate mean
Sigma_y = C;
mu_y = (sum(x)./length(Sigma_y)).';
end
Define the B vector as
b=zeros(length(A),1);
and compute the mean as
mu_y = (sum(x)./length(Sigma_y)).';

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by