Plotting a line with negative slope in Mathematica

Click For Summary
SUMMARY

This discussion focuses on plotting a line with a negative slope in Mathematica, specifically starting from the point (40, 0) with a length of 10 and an angle of 127 degrees from the x-axis. The user initially sought a solution similar to MATLAB's plotting capabilities. The provided Mathematica solutions include using the ListPlot function with a range for k and a parametric plot, both yielding the desired line representation. The exact Mathematica code shared is: k = Range[0,10,0.1]; x=40+k Cos[127 Degree]; y=0+k Sin[127 Degree]; ListPlot[Transpose[{x,y}], Joined->True] and ParametricPlot[{40 + t Cos[127 Degree], t Sin[127 Degree]}, {t, 0, 10}].

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of trigonometric functions and their application in plotting
  • Knowledge of coordinate geometry, specifically plotting lines
  • Basic experience with parametric equations
NEXT STEPS
  • Explore advanced plotting techniques in Mathematica, such as Graphics and Show
  • Learn about using Manipulate for interactive visualizations in Mathematica
  • Investigate the use of Graphics`Graphics` for more complex line and shape plotting
  • Study the differences between ListPlot and ParametricPlot for various plotting scenarios
USEFUL FOR

Mathematica users, data visualizers, educators, and students looking to enhance their skills in plotting and graphical representations of mathematical concepts.

yaang
Messages
22
Reaction score
0
I want to plot a line in mathematica with a negative slope by setting it's starting point, length, and slope but i couldn't figure out how to do it.

example: A line "AB"
has a starting point (40,0)
has a length 10
has an angle 127 degrees between x axisIn MATLAB i can do this with
%%
k = 0:0.1:10;
x=40+k*cosd(127);
y=0+k*sind(127);
plot(x,y)
%%
Result:http://i53.tinypic.com/2lb18x.pngHow can i do this with mathematica ? Can anyone help ? (I don't want to draw it from it's end point to beginning point )
 
Last edited:
Physics news on Phys.org
There are, of course, many ways to achieve this in Mathematica, but the exact analogue of your code would be:

k = Range[0,10,0.1];
x=40+k Cos[127 Degree];
y=0+k Sin[127 Degree];
ListPlot[Transpose[{x,y}],Joined->True]

You get the same result from

ParametricPlot[{40 + t Cos[127 Degree], t Sin[127 Degree]}, {t, 0, 10}]
 
Thanks for the detailed answer, first way you showed looks especially interesting.
 

Similar threads

Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K