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

38 次查看(过去 30 天)
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 个评论
Asvin Kumar
Asvin Kumar 2021-6-24
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?

请先登录,再进行评论。

采纳的回答

Sergio Manzetti
Sergio Manzetti 2021-6-24
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by