3
$\begingroup$

I have two functions, one that generates my x values and one that generates my y values, and I want to merge the data to get a single line plot. This is easily done in excel, but I can't figure out how to do it in mathematica. I did it in excel and it should look like this:excel plot. I have written a code that looks like this, where my x and y values are functions of theta

x = 1/72 Cos[θ] (2 + 2 Cos[θ] + 27 Sin[θ])

y = 1/72 Sin[θ] (2 + 2 Cos[θ] + 27 Sin[θ])

I'm pretty sure my issue is just not knowing which plotting function to use, but I could be wrong.

$\endgroup$
4
$\begingroup$

You need to use ParametricPlot:

ParametricPlot[{
   1/72 Cos[\[Theta]] (2 + 2 Cos[\[Theta]] + 27 Sin[\[Theta]]), 
   1/72 Sin[\[Theta]] (2 + 2 Cos[\[Theta]] + 27 Sin[\[Theta]])},
 {\[Theta], 0, Pi}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ u da man, vickto k $\endgroup$ – orphanpunter69 Apr 6 at 17:00
4
$\begingroup$
Clear["Global`*"]

ParametricPlotas pointed out by Victor K is the most straightforward approach. You could also Solve for y as a function of x.

sol[x_] = y /. Solve[{
     x == 1/72 Cos[θ] (2 + 2 Cos[θ] + 27 Sin[θ]),
     y == 1/72 Sin[θ] (2 + 2 Cos[θ] + 27 Sin[θ])}, 
    y, {θ}, Reals];

There are four branches to the solution

Length@sol[x]

(* 4 *)

Plot[Evaluate@sol[x], {x, -0.25, 0.25},
 PlotRange -> {{-0.25, 0.25}, {-0.02, 0.42}},
 MaxRecursion -> 10,
 AspectRatio -> 4/5,
 PlotLegends -> Automatic]

enter image description here

The corresponding ParametricPlot(the range of θ is extended to 2 Pi) is

ParametricPlot[{
  1/72 Cos[θ] (2 + 2 Cos[θ] + 27 Sin[θ]),
  1/72 Sin[θ] (2 + 2 Cos[θ] + 27 Sin[θ])},
 {θ, 0, 2 Pi},
 PlotRange -> {{-0.25, 0.25}, {-0.02, 0.42}}]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.