Intersection between 2 symbolic functions
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey!
I have 3 symbolic gaussian function and need to find the intersection between the two Gaussian components on the most right (which I'm guessing it might be the ones with higher mean value??). But I don't really know how to do this since I am not used to work with symbolic functions.
The code that got me here is the following one, would really appreciate if someone could help.
clear,clc
I = im2double(imread('rice.png'));
% a) Gaussian mixture distribution
X = reshape(I, [prod(size(I)), 1]);
gmModel = fitgmdist(X, 3, 'Replicates', 10); % Gaussian mixture distribution with k = 3, repeating 10 times
means = gmModel.mu'; % Means of the gaussian distributions
sigmas = [gmModel.Sigma(1),gmModel.Sigma(2),gmModel.Sigma(3)]; % Covariances of the gaussian distributions
compProp = gmModel.ComponentProportion; % Hights of the gaussian distributions
% Gaussian function corresponding to all components of the fitted model
gaussian1 = makedist('Normal','mu',means(1),'sigma',sigmas(1));
gaussian2 = makedist('Normal','mu',means(2),'sigma',sigmas(2));
gaussian3 = makedist('Normal','mu',means(3),'sigma',sigmas(3));
syms x m s p
f = symfun(p/(s.*sqrt(2*pi)).*(exp(-((x-m).^2)./(2.*(s.^2)))), [x, m, s, p]);
for k = 1:3
ff(k) = f(x, means(k), sqrt(sigmas(k)), compProp(k));
end
0 Kommentare
Antworten (1)
Zuber Khan
am 23 Feb. 2024
Hi,
I understand that you want to find the intersection between the two Gaussian components on the most right.
To find the intersection between the two rightmost Gaussian components, we first need to identify which components these are. Assuming these are the ones with the higher mean values, you can sort the components by their means.
[sortedMeans, sortIndex] = sort(means);
Now, "sortedMeans" contains the mean values in ascending order, and "sortIndex" contains the indices of the components in the sorted order. The two rightmost components will be the ones with the two highest means, which correspond to the last two elements in "sortedMeans".
Next, we can set up the symbolic equations for the two rightmost Gaussian components and solve for their intersection using "solve" function as follows:
% Continue from your existing code
% Sort the Gaussian components by their means to identify the two rightmost components
[sortedMeans, sortIndex] = sort(means);
% The indices of the two rightmost components
rightmostIndices = sortIndex(end-1:end);
% Define the symbolic Gaussian function using symfun
syms x m s p
ff = symfun(p/(s*sqrt(2*pi)) * exp(-((x-m)^2)/(2*s^2)), [x, m, s, p]);
% Create symbolic functions for the two rightmost Gaussian components
f_rightmost1 = ff(x, means(rightmostIndices(1)), sqrt(sigmas(rightmostIndices(1))), compProp(rightmostIndices(1)));
f_rightmost2 = ff(x, means(rightmostIndices(2)), sqrt(sigmas(rightmostIndices(2))), compProp(rightmostIndices(2)));
% Solve for the intersection points of the two rightmost Gaussian functions
intersectionPoints = solve(f_rightmost1 == f_rightmost2, x);
% If there are any intersection points, convert them to numeric values
if ~isempty(intersectionPoints)
numericIntersectionPoints = double(intersectionPoints);
end
To know more about creating symbolic scalar variables and functions, please refer to the following documentation page:
Further, for more information on creating symbolic functions, kindly refer to the following documentation page:
Also, in order to have better understanding about "solve" function, refer to the following documentation:
I hope this resolves your query.
Regards,
Zuber
0 Kommentare
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!