Making graph for quadratic function

5 次查看(过去 30 天)
Julia Ellen
Julia Ellen 2015-4-6
编辑: Satwik 2025-3-20
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 个)

Satwik
Satwik 2025-3-20
编辑:Satwik 2025-3-20
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!

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by