필터 지우기
필터 지우기

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