简体   繁体   中英

Am trying to plot the magnitude of a complex function in MATLAB

This is my code so far:

sigma = -8:0.1:0;
omega = -10:0.1:10;

[x,y] = meshgrid(sigma, omega);

s = x + y*j;

zz = (5^2)./(s.^2 + 2*0.4*5.*s + 5^2);
xx = real(s);
yy = imag(s);
surf(xx,yy,zz);

I am getting the error that I can not use a complex variable in the surf function. I know the issue is in the zz variable, but I do not know how to find the magnitude of a complex function. Here is exactly what I am trying to do: http://i.imgur.com/Y6Rw8y6.png

Use abs to get the magnitude of a complex number.

zz = (5^2)./(s.^2 + 2*0.4*5.*s + 5^2);
xx = real(s);
yy =imag(s);
surf(xx,yy,abs(zz));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM