Getting fprintf to display two different outputs from a function on the same line.

function [xVertex,yVertex] = PolyVertex(a, b, c)
%PolyVertex comoute the X and Y vertex of any polynomial given a, b, and c.
% Get a, b and c from y = ax^2 + bx + c and plug them in to get the x and y vertex
xVertrex = -(b/(2*a));
yVertex = (a*(xVertex^2)) + (b*xVertex) + c
end
% initialize a, b, and c
a = 3;
b = -6;
c = 4;
% call your function
% assign both outputs
PolyVertex(a, b, c);
% call fprintf to display the results in a single line
% use %d as the placeholder
% include descriptive text
fprintf("The X vertex is %d The Y vertex is %d " PolyVertex(a, b, c))
I'm having trouble getting the last line to print xVertex and yVertex.

Answers (1)

% initialize a, b, and c
a = 3;
b = -6;
c = 4;
% call PolyVertex and assign both outputs
[xV,yV] = PolyVertex(a, b, c);
% display the result
fprintf("The X vertex is %d The Y vertex is %d ", xV, yV)
The X vertex is 1 The Y vertex is 1
function [xVertex,yVertex] = PolyVertex(a, b, c)
%PolyVertex comoute the X and Y vertex of any polynomial given a, b, and c.
% Get a, b and c from y = ax^2 + bx + c and plug them in to get the x and y vertex
% xVertrex = -(b/(2*a)); % fixed typo "xVertrex"
xVertex = -(b/(2*a));
yVertex = (a*(xVertex^2)) + (b*xVertex) + c;
end

Categories

Products

Asked:

on 21 Jan 2024

Commented:

on 21 Jan 2024

Community Treasure Hunt

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

Start Hunting!