Plotting a line with negative slope in Mathematica

In summary, to plot a line with a negative slope in Mathematica, you can use the code "k = Range[0,10,0.1]; x=40+k Cos[127 Degree]; y=0+k Sin[127 Degree]; ListPlot[Transpose[{x,y}],Joined->True]" or "ParametricPlot[{40 + t Cos[127 Degree], t Sin[127 Degree]}, {t, 0, 10}]" to get the desired result.
  • #1
yaang
23
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
  • #2
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}]
 
  • #3
Thanks for the detailed answer, first way you showed looks especially interesting.
 

Related to Plotting a line with negative slope in Mathematica

1. How do I plot a line with negative slope in Mathematica?

To plot a line with negative slope in Mathematica, you can use the Plot function with the appropriate slope value. For example, if you want to plot a line with a slope of -2, you can use the code Plot[-2x, {x, 0, 10}]. This will create a line with a negative slope ranging from 0 to 10 on the x-axis.

2. Can I change the color or style of the line?

Yes, you can change the color and style of the line by adding additional parameters to the Plot function. For example, to change the color to red, you can add the parameter PlotStyle -> Red. To change the style to a dashed line, you can add PlotStyle -> Dashed.

3. How can I add labels to my plot?

To add labels to your plot, you can use the PlotLabel and AxesLabel parameters in the Plot function. For example, PlotLabel -> "My Line" will add a label at the top of your plot, and AxesLabel -> {"x-axis", "y-axis"} will add labels to the x and y axes.

4. Is it possible to plot multiple lines with negative slope on the same graph?

Yes, you can plot multiple lines with negative slope on the same graph by using the Plot function multiple times. For example, if you want to plot two lines with slopes -2 and -3, you can use the code Plot[{-2x, -3x}, {x, 0, 10}]. This will plot both lines on the same graph with different colors or styles.

5. Can I customize the range of the x and y axes?

Yes, you can customize the range of the x and y axes by using the PlotRange parameter in the Plot function. For example, PlotRange -> {{-5, 5}, {-10, 10}} will set the x-axis to range from -5 to 5, and the y-axis to range from -10 to 10. You can also use PlotRange -> All to automatically adjust the range based on the data being plotted.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
852
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
928
  • Advanced Physics Homework Help
Replies
5
Views
842
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
323
  • Set Theory, Logic, Probability, Statistics
Replies
11
Views
867
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
924
  • Engineering and Comp Sci Homework Help
Replies
1
Views
991
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top