Problems plotting a function

조회 수: 5 (최근 30일)
Sergio Manzetti
Sergio Manzetti 2017년 8월 7일
답변: Star Strider 2017년 8월 7일
Hi, I am trying to plot the result from the given script:
syms f(x) x g h
h = 1.0545718.*10.^-34
g = 5.33.*10.^-28
n = 2;
res = exp(-3.*x./2.*i.*g./h)
for k=1:n
res = simplify(diff(res,x) - x*res);
end
res = res
x = linspace(-10*pi, 10*pi, 1000);
s=res;
real_y1 = real(y);
imag_y1 = imag(y);
plot(real_y1,imag_y1,'LineWidth',2)
figure(1)
however, I get the strange complaint from Matlab:
Error using plot
Data must be numeric, datetime, duration or an array convertible to double.
Error in Operator_SUSY_Psi (line 15)
plot(real_y1,imag_y1,'LineWidth',2)
Which plotting function should I use?
  댓글 수: 1
Stephen23
Stephen23 2017년 8월 7일
You call plot with these variables:
real_y1 = real(y);
imag_y1 = imag(y);
plot(real_y1,imag_y1,'LineWidth',2)
but y is not defined anywhere in the code that you show us. So we have no idea what y is, other than it is clearly not numeric (as the error message clearly states).

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2017년 8월 7일
First, define ‘h’ as:
h = 1.0545718E-34;
Second, see if this does what you want:
x = linspace(-10*pi, 10*pi, 1000);
y=double(res(x));
real_y1 = real(y);
imag_y1 = imag(y);
figure(1)
plot(real_y1,imag_y1,'LineWidth',2)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by