How to build a complex system associated with its imaginary parts

I defined a complex symbolic system:

syms x sys(x) = ((10+1.*i.*x))/(20+(5.*i.*x)+((10.*i.*x).^2))+((1.*i.*x).^3); ImaginaryPart = imag(sys) RealPart = real(sys) 

MATLAB returned the following results:

 ImaginaryPart(x) = - real(x^3) + imag((10 + x*1i)/(- 100*x^2 + x*5i + 20)) RealPart(x) = - real(x^3) + imag((10 + x*1i)/(- 100*x^2 + x*5i + 20)) 

Now, how is it possible to plot(x,sys(x)) or (x,ImaginaryPart(x)) in a complex surface?

+6
source share
1 answer

To plot, you must use a range of values. So using x = a + b*i :

 [a,b] = meshgrid(-10:0.1:10); %// creates two grids ComplexValue = a+1i*b; %// get a single, complex valued grid CompFun = @(x)(- real(x.^3) + imag((10 + x.*1i)./(- 100.*x.^2 + x.*5i + 20))); %// add dots for element wise calculation result = CompFun(ComplexValue); %// get results pcolor(a,b,result) %// plot shading interp %// remove grid borders by interpolation colorbar %// add colour scale ylabel 'Imaginary unit' xlabel 'Real unit' 

enter image description here

I needed to add points (e.g. element multiplication) to your equation to make it work.

Also, contourf as suggested in the comment from @AndrasDeak :

 figure contourf(a,b,result,51) %// plots with 51 contour levels colorbar 

I used meshgrid -10:0.01:10 here for a larger resolution:

enter image description here

If you do not want to manually copy the solution to add multiplicative points to cartoons, you can resort to loops:

 grid = -10:0.1:10; result(numel(grid),numel(grid))=0; %// initialise output grid for a = 1:numel(grid) for b = 1:numel(grid) x = grid(a)+1i*grid(b); result(a,b) = ImaginaryPart(x); end end 

This gives the same result, but with pluses and minuses. This is slower than matrix multiplication, i.e. Adding points to your equation, but it does not require manual manipulation of the conclusions.

+9
source

All Articles