XMIN must be a floating point scalar. Kindly help me in clearing the error.

1 vue (au cours des 30 derniers jours)
Swathi S
Swathi S le 10 Sep 2019
CODE:
%all variables are declared
Mt1=0
for ai=a-2*(N-1)*wd-2*(N-1)*s:2*(wd+s):a-2*(N-N)*wd-2*(N-N)*s
for aj=a-2*(N-1)*wd-2*(N-1)*s:2*(wd+s):a-2*(N-N)*wd-2*(N-N)*s
k=(sqrt((4*ai*row)/((row.^2)+(d.^2)+(ai.^2)+(2*ai*row))))
Bz=@(y,x)(((u0./(2.*pi))*(1./((sqrt((row+ai)).^2+(d.^2)))).*(ellipticK(k)+(((ai.^2)-(row.^2)-(d.^2))./(((row-ai).^2)+(d.^2))).*ellipticE(k))))
yl=@(x) sqrt(aj^2-x^2)
M=integral2(Bz(x,y),-yl(x), yl(x), -aj, aj)
Mt1=Mt1+M
hold on
end
end
ERROR:
XMIN must be a floating point scalar.
XMIN must be a floating point scalar.
Error in FPSSCFINAL10Sep192 (line 108)
M=integral2(Bz(x,y),-yl(x), yl(x), -aj, aj)

Réponses (1)

Steven Lord
Steven Lord le 10 Oct 2019
Bz=@(y,x) <lengthy expression that doesn't depend on x OR y snipped>
yl=@(x) sqrt(aj^2-x^2)
M=integral2(Bz(x,y),-yl(x), yl(x), -aj, aj)
You're trying to evaluate the anonymous functions Bz and yl at some point or points and passing the numbers that are the results of those evaluations into integral2. Instead you're going to need to pass the anonymous functions themselves into integral2. That way integral2 can evaluate your functions at points of its choosing, not ones you've chosen for it.
Bz=@(y,x) <lengthy expression that doesn't depend on x OR y snipped>
yl=@(x) sqrt(aj^2-x^2);
minusyl = @(x) -yl(x);
M=integral2(Bz, minusyl, yl, -aj, aj)
Note too that integral2 is going to call your function with x and y coordinates, not y and x, so you'll need to either swap the order of inputs to Bz or add an adapter, much like I did to compute -yl(x), and pass the adapter in.
One additional flag, now that I go back and check: your Bz function doesn't actually depend on x or y. So effectively you're integrating a constant. If that's not your intention, you probably want to reexamine your derivation or original problem statement of Bz to determine how it should depend on x and/or y.

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by