For plotting it's required to 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'
I did have to add dots (i.e. element wise multiplication) to your equation to make it work.
Additionally with the contourf
as suggested in the comment by @AndrasDeak:
figure
contourf(a,b,result,51) %// plots with 51 contour levels
colorbar
I used a meshgrid of -10:0.01:10
here for more resolution:
If you are reluctant to hand-copy the solution to add the element wise multiplication dots, 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 delivers the same result, but with pros and cons both. It's slower than matrix-multiplication, i.e. than adding dots to your equation, but it does not require manipulating the output by hand.
contourf
instead/as well, with a lot of levels: zeroes are clearly visible then. – Placable