Error using mupadengine/feval_internal First argument must be a condition.
7 views (last 30 days)
Show older comments
Sergio Manzetti
on 21 Jun 2021
Commented: Sergio Manzetti
on 21 Jun 2021
Hi , I keep getting this error message "First argument must be condition" evidently regarding the set up in line 14 in the given code:
syms r x k z l m ph
% l=zeta1, m=zeta2
[ph,r] = meshgrid((0:5:360)*pi/180,0:.5:10);
[X,Y] = pol2cart(ph,r);
Z = X+1i*Y;
J = besselj(k,l.*r);
J2 = besselj(k,m.*r);
Y = bessely(k,l.*r);
Y2 = bessely(k,m.*r);
H = besselh(k,r);
F1=symsum(J.*exp(1i*k*ph),k,-5,5);
F2=symsum((J2+Y2).*exp(1i.*k.*ph),k,-5,5);
F3=symsum(H.*exp(1i.*k.*ph),k,-5,5);
pwu = piecewise(0<r & r<0.5, F1, 0.5<r & r<1, F2, r>1, F3);
U= subs(pwu, {l, m, r, ph}, {1.5, 3, 0<r & r<4, 0<ph & ph<2*pi });
surf(X,Y,double(real(U)))
hold on
surf(X,Y,zeros(size(X)))
hold off
Error using mupadengine/feval_internal
First argument must be a condition.
Error in sym/piecewise (line 49)
pw = feval_internal(symengine, 'piecewise', lists{:}, 'ExclusiveConditions');
Error in piecewi_u (line 14)
pwu = piecewise(0<r & r<0.5, F1, 0.5<r & r<1, F2, r>1, F3);
I am using r as a variable with phi (ph), and even if I change this variable, I get the same error again.
Can anyone suggest a fix of this code?
Thanks!
0 Comments
Accepted Answer
Walter Roberson
on 21 Jun 2021
syms k l m
% l=zeta1, m=zeta2
[ph, r] = meshgrid((0:5:360)*pi/180,[0:.05:0.5, 1:.5:10]);
[x, y] = pol2cart(ph,r);
Z = x + 1i*y;
J = besselj(k,l.*r);
J2 = besselj(k,m.*r);
Y = bessely(k,l.*r);
Y2 = bessely(k,m.*r);
H = besselh(k,r);
F1 = symsum((J).*exp(1i*k*ph),k,-5,5);
%F1 = symsum((J+Y).*exp(1i*k*ph),k,-5,5);
F2 = symsum((J2+Y2).*exp(1i.*k.*ph),k,-5,5);
F3 = symsum(H.*exp(1i.*k.*ph),k,-5,5);
pwu = nan(size(F1), 'like', F1);
mask = 0 <= r & r < 0.5;
pwu(mask) = F1(mask);
mask = 0.5 <= r & r < 1;
pwu(mask) = F2(mask);
mask = r >= 1;
pwu(mask) = F3(mask);
U = subs(pwu, {l, m}, {1.5, 3});
surf(x, y, real(double(U)))
hold on
surf(x, y, zeros(size(x)))
hold off
You created Y but you did not use it. By parallelism with F2 it looks like you would want (J+Y) for F1 instead of just J. I show that version in a comment. The difference is fairly noticable, because at r = 0, bessly(k,0) is infinite, and you get infinities and NaN showing up.
Your boundary conditions were broken: you excluded the cases where r was exactly the boundaries, but those were important cases.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!