Plotting Only Purely Real Sections of function with fimplicit

10 views (last 30 days)
I am plotting an implicit function that only contains values within a very specific range of values. For better or worse, MatLab is also able to calculate this function in regions where it is complex, however, I am not interested in any of these solutions. I understand if instead of using fimplicit I instead can create an array of values which I know solutions should be in, then use those to find the other variables and just use plot, but I was wondering if anyone knew of anyways to plot only the purely real portions of the function.
Note: Currently MatLab is plotting all the real components of the function, but this means that there are sections where there are also imaginary components that are being ignored, I would just like to plot the parts of the function that are purely real.
I appreciate any help, thanks!
  2 Comments
Matt J
Matt J on 19 Sep 2023
Edited: Matt J on 19 Sep 2023
Currently MatLab is plotting all the real components of the function, but this means that there are sections where there are also imaginary components that are being ignored
I'm skeptical of that, based on the following example. In this example, f(x,y) has a zero real component and non-zero imaginary component for all y=x<=0, but fimplicit does not include that region in the plot.
f=@(x,y) (y-x) +1i*(x<=0).*x.^2;
f(-1,-1)
ans = 0.0000 + 1.0000i
fimplicit(f,[-2,2])
Andrew
Andrew on 19 Sep 2023
So this is the exact behavior going on. Like you said it is completely imaginary when y=x <= 0, meaning the real component is zero. For example,if in your case the solutions below 0 would be complex having both a real and imaginary compoenent, matlab seems to be plotting just the real component in these sections.

Sign in to comment.

Accepted Answer

Nipun
Nipun on 4 Oct 2023
Hi Andrew,
I understand that you have a function that maps values from input on a complex plane, and you are only interested in those output mappings which yield purely real values.
Using fimplicit, you can plot the function across a given range on a 2D cartesian plane. According to the documentation of fimplicit attached below, it will only plot the purely real values on the plot. For instance, consider the function
f = @(x,y) (y-x^2) + 1i*x;
fimplicit(f,[-10,10]);
Note that the returned plot will not have any values, since the returned values are not purely real. I should remark that fimplicit will not plot the real part of the value; it will only plot the purely values.
If you wish to try a different approach, you may consider designing a special function handle that only outputs purely real points from the main function. An example as follows:
f_out = @(x,y) f(x,y)*(isreal(f(x,y))) + 1i*(~isreal(f(x,y)));
fimplicit(f_out,[-10,10]);
isreal() gives a logical answer 1 is the passed argument is purely real, else it outputs 0. You will notice that f_out and f will give the same plots for a given range, for any predefined f.
Links to documentation:
  1. Plot implicit function - MATLAB fimplicit - MathWorks India
  2. Determine whether array uses complex storage - MATLAB isreal - MathWorks India
Hope this helps.
Nipun

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!