Plotting a line with negative slope in Mathematica

AI Thread Summary
To plot a line with a negative slope in Mathematica, you can use the code snippet that defines the starting point, length, and angle. The equivalent of MATLAB's plotting method involves creating a range for the variable k and calculating x and y coordinates using trigonometric functions. The suggested code 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]. Alternatively, you can use ParametricPlot with the same parameters to achieve the desired result. This approach effectively allows for plotting lines with specific characteristics in Mathematica.
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.
 
Back
Top