MATLAB: How to make one 53228×1 double matrix a function of another 53228×1 double matrix

arraydouble matrixfunctionmatrixnested function

I have two matrixes, GalList.mass and GalList.dist, that I need to create a singular function out of.
Both have dimensions of a 53228×1 double matrix.
GalList.mass is essentially a collective matrix of masses in the universe, while GalList.dist is a collective matrix of the distances of galaxies in the universe. I need to make a mass a function of distance, or M(r), but I do not know how to do that. I have tried nested functions, but that did not help.
SIDE NOTE: X1 = GalList.dist Y1= GalList.mass
I am fairly new to Matlab, so any help would be appreciated!

Best Answer

  • Is the mass predicted by the equation:
    Mass = rho*(4/3)*pi*(X1).^3
    the mean mass or the total mass as a function of distance?
    If it’s the total mass (since the equation is similar to the volume of a sphere), then fitting the equation to the cumulative sum of the ‘Y1’ masses as a function of the ‘X1’ distances might well follow the cubic relation.
    If you then are confident of ‘rho’ and you only want to estimate the exponent, you can use a nonlinear regression function (such as nlinfit) to estimate the parameter of:
    M = @(b,x) rho*(4/3)*pi*(X1).^p;
    and if you want to estimate both ‘rho’ and the exponent as parameters, use:
    M = @(b,x) b(1).*(4/3).*pi.*(X1).^b(2);
    fitting the appropriate version of ‘M’ as your objective function in nlinfit, depending on what you want to do.
    Just a guess on my part. This is far from my areas of expertise.