Quadratic formula using function with a single input and single output?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
amateurintraining
am 22 Sep. 2017
Bearbeitet: James Tursa
am 22 Sep. 2017
I am trying to write a code to solve the quadratic formula. But the function I am using uses the input: coef (the coefficients in a quadratic function as [a b c]) and the output: roots (which displays the positive and negative roots as a 2x1 array).
I know how to write the code if the inputs were a, b, and c however, I'm stuck on how to correlate coef with [a b c].
0 Kommentare
Akzeptierte Antwort
James Tursa
am 22 Sep. 2017
Bearbeitet: James Tursa
am 22 Sep. 2017
In your function, you could just extract the elements of coef into your a, b, and c variables if you wanted to. E.g.,
function roots = my_quadratic_formula(coef)
a = coef(1);
b = coef(2);
c = coef(3);
:
% then your code that uses a, b, c, goes here
And then assign the outputs:
roots(1) = _______; % <-- you fill in this code
roots(2) = _______; % <-- you fill in this code
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Quadratic Programming and Cone Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!