draw graph of y=x^2 in matlab

You can use the plot function in MATLAB to draw the graph of y = x^2.

Here is an example code snippet:

main.m
x = -10:0.1:10;   % Range of x values
y = x.^2;        % Calculate y values

plot(x, y)       % Plot the graph

% Add labels and title
xlabel('x')
ylabel('y')
title('Graph of y = x^2')

% Add grid lines
grid on

%Adjust the axis limits if needed
%axis([-10 10 0 100])

269 chars
17 lines

This code will create a graph with the range of x values from -10 to 10 with a step of 0.1. The y values are calculated as the square of each x value. The graph is then plotted using the plot function. You can also customize the labels, title, and grid lines as needed.

related categories

gistlibby LogSnag