Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MatLab Plot

  1. Mar 13, 2015 #1


    User Avatar
    Gold Member

    Hi PF!

    I am trying to run the following plot:

    k = .001;
    hold on
    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;

    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!

  2. jcsd
  3. Mar 13, 2015 #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" ?
  4. Mar 13, 2015 #3


    User Avatar
    Gold Member

    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?
  5. Mar 14, 2015 #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.
  6. Mar 14, 2015 #5


    User Avatar
    Gold Member

    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?
  7. Mar 15, 2015 #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.
  8. Mar 16, 2015 #7


    User Avatar
    Gold Member

    Thanks, this is very helpful! I really appreciate your time!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: MatLab Plot
  1. Plotting in matlab (Replies: 0)

  2. MATLAB plots (Replies: 1)

  3. Matlab Plot (Replies: 2)

  4. Plotting in MATLAB (Replies: 8)

  5. Plotting with MATLAB (Replies: 1)