Problems plotting a function

5 vues (au cours des 30 derniers jours)
Sergio Manzetti
Sergio Manzetti le 7 Août 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 commentaire
Stephen23
Stephen23 le 7 Août 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).

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 7 Août 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)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by