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

Drawing more Complicated Graphs in Mathematica

  1. Dec 12, 2009 #1
    I have a function, S[q] which is obtained by integrating another function, A[r,q] over r.

    My problem is that the lower limit of integration,
    rmin depends on q in a complicated manner. Mathematica can however solve this equation to give several routes, only one of which is real which is the one I want.

    I have a second function too, L[q] which is also obtained by integrating B[r,q] over r. Again the lower limit of integration depends on q in the same manner.

    What I want to do is for a given value of q, solve
    the equation for rmin, and use this to calculate
    the corresponding L[q]. I then wish to calculate
    S[q] in the same manner.

    I want Mathematica to do this for many values of
    q over a range and use the results to plot
    S[q] against L[q]. Does anyone know an efficient
    way to do this?

    Thank you for your help.
  2. jcsd
  3. Dec 12, 2009 #2


    Staff: Mentor

    I am not sure I follow your plan very well, but you certainly can make a table where each entry is the solution for a given value of q.
  4. Dec 12, 2009 #3
    Would it be possible to get Mathematica to plot a curved graph from a table like that if you do not know what it is supposed to look like to start with?
  5. Dec 13, 2009 #4


    Staff: Mentor

    You can either use ParametricPlot or ListParametricPlot depending on if you want to explicitly generate the table of data points, or if you want Mathematica to handle that internally.
  6. Feb 19, 2011 #5
    @hufflepup:dude i too have the same problem.:confused:.
    r u able to get nw?
    let me know if u cn..
  7. Feb 19, 2011 #6
    Hi sauberss,

    you can solve a problem like this as follows:

    If F[q] = integral^Infinity_rmin A[r,q]dq

    G[q] = integral^Infinity_rmin B[r,q] dq

    where ^Infinity and _rmin represent the upper and lower limits of integration respectively, and
    rmin= a(q)

    Mathematica code:

    F[q_]:= NIntegrate[A[r,q], {r, rmin, Infinity}]

    G[q_]:=NIntegrate[B[r,q], {r, rmin, Infinity}]

    The_]:= notation defines what is called a pattern, and basicly means that these expression won't be evaluated until they are called later, when a specific value of q will be provided.

    As the lower limit of integration depends on rmin you now have 2 options, which is easiest will depend on your specific setup:

    1) Get Mathematica to solve for rmin in terms of q, rmin=z(q), then replace rmin in the above equations with z(q).

    2) Solve for q in terms of rmin, q=w(rmin) and replace the q in the integrals with w(rmin) in which case your equations would look like:

    F[rmin_]:= NIntegrate[A[r,rmin], {r, rmin, Infinity}]

    G[rmin_]:=NIntegrate[B[r,rmin], {r, rmin, Infinity}]

    Note that these are of the form F[rmin_] not F[w(rmin)_] becuse the expression in the []
    just telss Mathematica which variables will be replaced with numbers later.

    To plot your graphs you then do:

    graphname = ParametricPlot[{F[q], G[q]}, {q, qmin, qmax}]


    graphname = ParametricPlot[{F[rmin], G[rmin]}, {rmin, rminmin, rminmax}]

    depending whether you went down path 1) or 2)

    where qmin/rminmin and qmax/rminmax define the range of q/rmin over which you want to plot the graph.

    I hope this helps you.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook