# \[Solved\] I have Plot issue in Mathematica code. Kindly sort it out.

**URL:** <https://community.wolfram.com/t/solved-i-have-plot-issue-in-mathematica-code-kindly-sort-it-out/16460>\
**Category:** Questions\
**Tags:** equation-solving, graphics-and-visualization\
**Created:** [July 18, 2020, 1:26pm UTC](https://community.wolfram.com/t/solved-i-have-plot-issue-in-mathematica-code-kindly-sort-it-out/16460 "2020-07-18T13:26:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanialikhan77](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@nanialikhan77](https://community.wolfram.com/u/nanialikhan77)\
**Post date:** [July 18, 2020, 1:26pm UTC](https://community.wolfram.com/t/solved-i-have-plot-issue-in-mathematica-code-kindly-sort-it-out/16460/1 "2020-07-18T13:26:38Z")

</div>

![Capture.PNG](https://global.discourse-cdn.com/wolfram/original/2X/0/03bc71efad1ac0b044a82578d6809540096ce60d.png)

This graph is plotted from equation:

```
    M=1;a;0.7;b=1.1754;
    r^2 + a^2 Cos[\[Theta]]^2 - 2 M (1 - (2.718)^(-r^3/b^3)) r .
    M = 1; a = 0.4; b = 1; NSolve [{r^2 + a^2 Cos[\[Theta]]^2 - 
        2 M (1 - (2.718)^(-r^3/b^3)) r == 0, 0 <= r <= 8}, r]

    ParametricPlot[{rSin[\[Theta]], rCos[\[Theta]]} {\[Theta], -\[Pi], \[Pi]}]

```

It is solved numerically for r but no \theta is value initially put in the equation otherwise it gives a circle and I need the plot as above mentioned (Parametrically plotted or Polar Plotted).

---

<div class="post-metadata">

**Author:** ![nikolayshilov1997](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/nikolayshilov1997/32/7843_2.png) [@nikolayshilov1997](https://community.wolfram.com/u/nikolayshilov1997)\
**Post date:** [July 19, 2020, 5:52am UTC](https://community.wolfram.com/t/solved-i-have-plot-issue-in-mathematica-code-kindly-sort-it-out/16460/2 "2020-07-19T05:52:57Z")

</div>

First, I suppose that your piece of code is kind of messy, so I picked just a part of it and recasted into “supposed-to-work” Wolfram code:

```
M = 1;
a = 0.4;
b = 1;

r = NSolve[{r^2 + a^2 Cos[\[Theta]]^2 - 2 M (1 - (2.718)^(-r^3/b^3)) r == 0, 0 <= r <= 8}, r];
ParametricPlot[{r * Sin[\[Theta]], r * Cos[\[Theta]]}, {\[Theta], -\[Pi], \[Pi]}]

```

If got your idea correctly then here’s my explanation and the solution.

The problem is that NSolve (as far as I know) does not allow use of unset parameters like “Theta” in the equation it solves, so the right-hand-side of the penultimate line in the code above remains unevaluated. Then, NSolve returns a list of replacement rules, not numbers. Finally, the solution might be not unique; for example, for the mentioned values of paramters **M** , **a** and **b** and **Theta** = Pi there are two solutions for **r** whithin [0, 8] interval.

So, I came up with the following code:

```
sol[\[Theta]_] := NSolve[{r^2 + a^2 Cos[\[Theta]]^2 - 2 M (1 - (2.718)^(-r^3/b^3)) r == 0, 
0 <= r <= 8}, r]

ParametricPlot[
 Transpose[{(r /. sol[\[Theta]] )* 
    Sin[\[Theta]], (r /. sol[\[Theta]] )* 
    Cos[\[Theta]]}] , {\[Theta], -\[Pi], \[Pi]}]

```

This code works like this: the equation for **r** is solved numerically for each value of Theta inside the **ParametricPlot** function and the solutions are substituted in place of **r**. Transposition is required to form different curves for each branch of solutions. This is probably not the most efficient solution, but it works. I got this plot:

 ![parametricplot.png](https://global.discourse-cdn.com/wolfram/original/2X/f/f292cd052b58812dc8fda918ea3a497e059214df.png)

P.S. The strange thing is that your equation does not have solutions in the specified domain for Theta = Pi and the first set of parameters:

`M=1; a = 0.7; b=1.1754;`

---

<div class="post-metadata">

**Author:** ![nanialikhan77](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@nanialikhan77](https://community.wolfram.com/u/nanialikhan77)\
**Post date:** [July 19, 2020, 6:21am UTC](https://community.wolfram.com/t/solved-i-have-plot-issue-in-mathematica-code-kindly-sort-it-out/16460/3 "2020-07-19T06:21:10Z")

</div>

Thank you for the reply. I am satisfied with your solution.
