Problems plotting a function

5 views (last 30 days)
Sergio Manzetti
Sergio Manzetti on 7 Aug 2017
Answered: Star Strider on 7 Aug 2017
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 Comment
Stephen23
Stephen23 on 7 Aug 2017
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).

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 7 Aug 2017
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)

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!