Making graph for quadratic function
10 views (last 30 days)
Show older comments
I'm very new to MatLab and I am having some difficulty creating the code and just understanding what to put where. I got my quadratic formula to run and loop(Ex 4.2), but now I've been asked to have a function to plot the graph of the formula.
These are my instructions:
Meet all the requirements of Ex 4.2 • Prompt the user for the vector of X values at which the quadratic will be evaluated. Note: the statement: XVec = input(‘Enter X vector’); Will quite happily deal with any valid Matlab vector specification. For example, inputting: -100:10:100 will give you a vector of numbers from -100 to 100 in increments of 10. • Plot the graph, label the X and Y axes, and add a title.
This makes me more confused as I don't know where to add these new statements, and the quadratic formula gives 2 values for x, how do I even get all of this input working??

1 Comment
Answers (1)
Satwik
on 20 Mar 2025
Edited: Satwik
on 20 Mar 2025
Hi @Julia,
I understand that the goal is to evaluate and plot a quadratic function using a MATALAB script. Here is an example script which you may refer to:
% Define the coefficients of the quadratic
a = 1; % Example coefficient for x^2
b = -3; % Example coefficient for x
c = 2; % Example constant term
% Prompt the user for the vector of X values
XVec = input('Enter X vector: ');
% Calculate the quadratic values using the formula y = ax^2 + bx + c
YVec = a * XVec.^2 + b * XVec + c;
% Plot the graph
figure; % Open a new figure window
plot(XVec, YVec, '-o'); % Plot with line and circle markers
xlabel('X values'); % Label for X-axis
ylabel('Y values'); % Label for Y-axis
title('Quadratic Function Plot'); % Title of the plot
I hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!