Optimizing Plotting for Complex Functions with Large Numbers

Click For Summary

Discussion Overview

The discussion revolves around optimizing the plotting of complex functions with large numerical values in MATLAB. Participants explore issues related to contour plotting, normalization of parameters, and the impact of constants on the visual representation of the function.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant shares a MATLAB plotting script that works well for small constants but fails to produce a satisfactory plot with larger values.
  • Another participant suggests that there may be parameters to control contour levels and questions what is meant by "not a good plot."
  • A participant clarifies that the new plot looks significantly different from the original, implying that the constants affect the graph more than expected.
  • One suggestion is to normalize the function and the variables to improve control over the ranges and sampling, potentially addressing issues with rapidly changing regions.
  • Another participant proposes introducing new variables to scale the function, reducing the number of constants involved.
  • A question is raised about handling the origin in the function, as it approaches infinity at that point.
  • It is mentioned that the contour3() function has parameters that can alter contour levels, suggesting that reading MATLAB documentation may provide additional options.

Areas of Agreement / Disagreement

Participants express multiple competing views on how to address the plotting issues, with no consensus reached on the best approach. Suggestions for normalization and parameter adjustments are discussed, but differing opinions on the effectiveness of these methods remain.

Contextual Notes

Limitations include the dependence on specific parameter values and the potential for unresolved mathematical steps related to normalization and contour plotting.

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
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" ?
 
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?
 
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.
 
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?
 
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

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

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   Reactions: member 428835
Thanks, this is very helpful! I really appreciate your time!
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K