Making graph for quadratic function

조회 수: 11 (최근 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
Khairul Azam
Khairul Azam 2020년 10월 19일
i realy tired to alive... can you give me some advice

댓글을 달려면 로그인하십시오.

답변 (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