Getting fprintf to display two different outputs from a function on the same line.
Afficher commentaires plus anciens
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.
Réponses (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)
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
1 commentaire
DYLAN
le 21 Jan 2024
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!