Optimizing Plotting for Complex Functions with Large Numbers

In summary, the conversation discusses troubleshooting a plot in MATLAB using a for loop and contour3 function. The speaker suggests normalizing the function and using a scaling factor to improve the plot. They also mention adjusting the contour levels and possibly using Gnuplot as an alternative.
  • #1
member 428835
Hi PF!

I am trying to run the following plot:

k = .001;
figure;
hold on
[X,Y]=meshgrid(-4:0.01:4);
a = 5.56*10^14;
b = .15/(2*.143*10^(-6));
for n = 1:8
k = k*2^(n-1);
Z = a./(X.^2+Y.^2).*exp(b.*(X-sqrt(X.^2+Y.^2)))-k;
contour3(X,Y,Z)
end

which works great if a = b = 1. But now when the numbers are big, I'm not getting a good plot. Any ideas how to remedy this?

Thanks so much!

Josh
 
Physics news on Phys.org
  • #2
I think that there was a parameter to control the number of contour levels, somehow it was also possible to explicitly give the conour level values to be ploted. What do you mean by "not a good plot" ?
 
  • #3
Sorry for the ambiguity. By "not a good plot" I mean the new plot looks nothing even remotely similar to the original. I know constants will change the graph, but not to this extent.

Are you suggesting I change the k values?
 
  • #4
The values of a and b resamble some physical constants, you should normalize your function and reduce the number of constants involve. Normalize x and y in terms of a and normalize the function value in terms of k and a/b ratio. In this way you have a better control of the ranges of x, y and f(x,y). Otherwise rapidly changing regions may receive a poor samplig and will look not so good.
 
  • #5
Ahhhh, good idea! So you saying let the function equal itself divided by a, right? and then let (X-sqrt(X.^2+Y.^2)) equal itself divided by b?
 
  • #6
We introduce new variables ##x_1=x/\sqrt{b}## and ##y_1=y/\sqrt{b}## and the new function let's say ##f_1(x_1,y_1)## will read

[tex]f_1(x_1,y_1)=\frac{c}{x_1^2+y_1^2} \exp(x_1 -\sqrt{x_1^2 + y_1^2} )[/tex]

with ##c=a/b##. We are left with only one constant in the function, ##c## beeing a scaling factor for the values of the function.
How do you handle the origin, i.e. ##(x,y)=(0,0)## ? The function ##f## goes to infinity!

On the other hand I think that you don't need to rest the ##k## value in order to obtain the contour level. The contour3() function receives a fourth parameter which alter the contour levels (step number, interval). You must read the MATLAB help to see whether any option may result useful in your case. I remember that several years ago I was forced to use Gnuplot insead of Mathlab because some specific plot options were not available.
 
  • Like
Likes member 428835
  • #7
Thanks, this is very helpful! I really appreciate your time!
 

FAQ: Optimizing Plotting for Complex Functions with Large Numbers

1. What is a complex function?

A complex function is a mathematical function that takes a complex number as its input and produces a complex number as its output. It can be represented as f(z) = u(x,y) + iv(x,y), where z = x + iy, u and v are real-valued functions, and i is the imaginary unit.

2. How do you plot a complex function?

To plot a complex function, you can use a complex plane or Argand diagram. The horizontal axis represents the real part of the input and the vertical axis represents the imaginary part. Then, you can evaluate the function for different values of z and plot the corresponding points on the complex plane.

3. What is the significance of the modulus and argument in a complex function?

The modulus of a complex function is the distance from the origin to the point representing the output value on the complex plane. The argument is the angle between the positive real axis and the line connecting the origin to the point representing the output value. These values help us understand the behavior of the complex function and its relationship with the input value.

4. How do you determine the domain and range of a complex function?

The domain of a complex function is the set of all complex numbers for which the function is defined. It can be determined by looking at the restrictions on the input variables in the function. The range of a complex function is the set of all possible output values. It can be determined by evaluating the function for different input values and observing the output values.

5. Are there any special techniques for plotting complex functions?

Yes, there are some techniques that can make plotting complex functions easier. One such technique is using color to represent the phase or argument of the output value. Another technique is using 3D plots to show the real and imaginary parts of the output value as well as the modulus. Additionally, using contour plots can help visualize the behavior of a complex function in a particular region of the complex plane.

Similar threads

Replies
8
Views
801
Replies
2
Views
1K
Replies
2
Views
1K
Replies
11
Views
3K
Replies
2
Views
3K
Replies
1
Views
2K
Back
Top