Plot Parabola from -20 to 20 in MATLAB

  • MATLAB
  • Thread starter mishal
  • Start date
  • Tags
    Matlab
In summary, to plot a parabola from -20 to 20 in MATLAB, you can use the "plot" function and specify the range of x-values as well as the equation for the parabola. This will generate a graph of the parabola on the specified range, with the vertex at the origin and the curve opening upwards. You can also customize the appearance of the graph by adding a title, labels, and adjusting the axis limits. Additionally, you can use the "fplot" function to plot a parabola defined by a function handle, which allows for more flexibility in the equation used.
  • #1
mishal
3
0
Plot the parabola which has the equation y = x^2+2x+3 for -20<x<20 using Matlab.
 
Physics news on Phys.org
  • #2
need the solution
 
  • #3
Hey, mishal,

This is the simple solution to your problem:
x = -20:0.01:20;
y = x.^2 + 2*x + 3;
plot(x,y);

You can copy and paste this into your Matlab Command Prompt. If you need more information, feel free to ask me.

By the way, you can search Matlab Help, that's very good source for self learning. And you can go to: http://www.mathworks.com/matlabcentral/index.html" to find more .m files that might help you.

PS: Mathematics is a suitable source for this kind of question. (Or Homework or Coursework questions)
 
Last edited by a moderator:
  • #4
TChi, this is a particularly simple question, so what you did isn't particularly egregious, but we here at PhysicsForums try to help people work through their problems (especially when it's homework). Homework should be in the Homework section (there's an Engineering and CompSci section), but there's also a Computer Science and Programming subforum as well (and there's a Mathematical Software section within that--for things like MATLAB, Octave and/or Mathematica)

EDIT: mods will occasionally delete responses that out-and-out answer questions (that should be answered by the question asker), and move homework to appropriate subforums. Not to snerk, just to let you know.
 
  • #5
hey thankyou so much for your kind information
 

1. How do I plot a parabola in MATLAB?

To plot a parabola in MATLAB, you can use the plot function along with the x^2 notation. For example, if you want to plot a parabola with the equation y = 2x^2, you would use the following code: plot(x, 2*x^2). Make sure to define the range of x values you want to plot.

2. Can I plot a parabola with a different range of values?

Yes, you can plot a parabola with a range of values other than -20 to 20. Simply define the range of x values in the plot function. For example, if you want to plot the same parabola from -10 to 10, you would use plot(-10:10, 2*(-10:10)^2).

3. How can I change the color of the parabola?

To change the color of the parabola, you can use the color parameter in the plot function. For example, if you want to plot a red parabola, you would use plot(x, 2*x^2, 'color', 'red'). You can also use other colors such as 'blue', 'green', 'yellow', etc.

4. Is it possible to add a title and axis labels to the plot?

Yes, you can add a title and axis labels to the plot by using the title, xlabel, and ylabel functions. For example, if you want to add a title to your plot, you would use title('Parabola Plot'). Similarly, you can add labels to the x-axis and y-axis using xlabel and ylabel respectively.

5. Can I add a grid to the plot?

Yes, you can add a grid to the plot by using the grid function. Simply use grid on to turn on the grid lines, or grid off to turn them off. You can also change the appearance of the grid lines by using parameters such as 'color', 'linestyle', and 'linewidth'.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top