Making graph for quadratic function

17 ビュー (過去 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 Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by