Error using Contour: input arguments must be numeric or objects which can be converted to a double

38 views (last 30 days)
Hi, I have the given code where I try to plot levels curves of the givenfunction
syms r x y k z
[ph,r] = meshgrid((0:5:360)*pi/180,0:.5:10);
[X,Y] = pol2cart(ph,r);
Z = X+i*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 = 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});hold on
contour(X,Y,imag(double(U)),30)
axis equal
xlabel('r','FontSize',14);
ylabel('phi','FontSize',14);
But I get an error for the 4th last line. How can this be made in a way it is converted to a double?
Thanks!
  1 Comment
Asvin Kumar
Asvin Kumar on 24 Jun 2021
I'm not able to run this script because the variables l, m, n, etc are not defined. Could you update the attached code so that your error can be reproduced?

Sign in to comment.

Accepted Answer

Sergio Manzetti
Sergio Manzetti on 24 Jun 2021
Yes, here it is, working script
syms r x y k z l m
[ph,r] = meshgrid((0:5:360)*pi/180,0:.5:10);
[x,y] = pol2cart(ph,r);
Z = x+1i*y;
J = 0.9426656*besselj(k,l.*r);
J2 = 0.640840882*besselj(k,m.*r);
Y = bessely(k,l.*r);
Y2 = 0.4361500838*bessely(k,m.*r);
H = 1.1159118143*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 = 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});hold on
w=double(U)
contour(x, y, angle(double(U)), 30);
axis equal
xlabel('r','FontSize',14);
ylabel('phi','FontSize',14);

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!