MATLAB Answers

Constraints on meshgrid. Remove points outside function

12 views (last 30 days)
I need help constraining the entries in my meshgrid. So far the entries take values on the entire x-axis and y-axis.
I have a figure consisting of an upper curve and a lower curve. Any point outside the curves should be equal to nan and not be coloured.
M = 3749.41; %MeV
m1 = 3728.4; %MeV
m2 = 0.5109989461; %MeV
m3 = 0.5109989461; %MeV
lambda = @(x,y,z) (x-y-z).^2-4*y*z; %Triangle function
s = M^2; %Mass of the decaying particle squared
s1 = linspace((m1+m2).^2,(sqrt(s)-m3)^2,1000); %s1 = s12
s2 = linspace((m2+m3).^2,(sqrt(s)-m1)^2,1000); %s2 = s23
s3 = linspace((m1+m3).^2,(sqrt(s)-m2)^2,1000); %s3 = s31
s11 = @(s2) m1^2+m2^2-1./(2*s2).*((s2-s+m1^2).*(s2+m2^2-m3^2)-lambda(s2,s,m1^2).^(1/2).*lambda(s2,m2^2,m3^2).^(1/2)); %upper half of boundary curve
s12 = @(s2) m1^2+m2^2-1./(2*s2).*((s2-s+m1^2).*(s2+m2^2-m3^2)+lambda(s2,s,m1^2).^(1/2).*lambda(s2,m2^2,m3^2).^(1/2)); %lower half of boundary curve
hold on
mr = 0.0167*1000; %Pole mass in MeV
gamma01 = 0.002*1000; %Decay width in MeV
A1 =@(a) sqrt(a)./(mr^2-a-1i*gamma01*sqrt(a)); %Breit-Wigner
T0 = 1;
Matrixelement = @(b) T0.*A1(b);
costheta = @(s1) 2.*(sqrt(s1)-min(sqrt(s1)))./(max(sqrt(s1))-min(sqrt(s1)))-1;
lpol = @(s1) legendreP(1,costheta(s1));
A1 =@(a) sqrt(a)./(mr^2-a-1i*gamma01*sqrt(a));
[x,y] = meshgrid(s2,[s11(s2),s12(s2)]);
hold on
mscale1 = @(x) (Matrixelement(s2) - min(Matrixelement(s2)))./( max(Matrixelement(s2)) - min(Matrixelement(s2))); %normalize
mscale2 = @(a) (Matrixelement(s2) - min(Matrixelement(s2)))./( max(Matrixelement(s2)) - min(Matrixelement(s2))); %normalize
z = (mscale1(x).*conj(mscale1(x))).*costheta(y).^2; %abs(1/2.*(3.*costheta(y).^2-1)); %remember spin
All I need is to make the meshgrid only to take values inside the curve.


Sign in to comment.

Accepted Answer

Matt J
Matt J on 16 May 2020
Just apply logical indexing on the appropriate region and set it to NaN,
bad=(y<s11(s2)) | (y>s12(s2));


Show 2 older comments
Martin Mikkelsen
Martin Mikkelsen on 17 May 2020
Like this?
[xrect,yrect] = meshgrid(s2,[s11(s2),s12(s2)]);
bad=(y<s11(s2)) | (y>s12(s2));
mscale1 = @(x) (Matrixelement(s2) - min(Matrixelement(s2)))./( max(Matrixelement(s2)) - min(Matrixelement(s2))); %normalize
z = abs(Matrixelement(x)).^2+costheta(y); %abs(1/2.*(3.*costheta(y).^2-1)); %remember spin
There seems to be only one value of zrect not equal to nan now. Am I missing something?
Matt J
Matt J on 17 May 2020
Check to make sure you’ve constructed the logical array “bad” correctly.
Martin Mikkelsen
Martin Mikkelsen on 17 May 2020
I changed it to
bad=(y>=s11(s2)) | (y<=s12(s2));
And that fixed the problem. Thank you so much! I really appreciate it.

Sign in to comment.

More Answers (0)

Translated by