how do i make this function accept vector values ?
Mostrar comentarios más antiguos
hi , i have this function of the quadratic formula and i have had trouble getting it to accept vector values ?
function [ Root] = Quadratic( a, b ,c , plusOrMinus )
%UNTITLED6 Summary of this function goes here
% inputs coeffecients
if ((b^2)-4.*(a).*(c)) > 0
Num = -b +(plusOrMinus)* sqrt((b.^2)-(4.* a.* c));
denom = 2.*(a);
Root = Num/denom;
else
error(' the coeffecients yield a complex root')
end
Respuestas (1)
James Tursa
el 15 de Feb. de 2017
Editada: James Tursa
el 15 de Feb. de 2017
Assuming you want to yield an error if any of the values yield complex roots, e.g.,
function [ Root] = Quadratic( a, b ,c , plusOrMinus )
%UNTITLED6 Summary of this function goes here
% inputs coeffecients
% Khaled Almutairi, u1055414, ME EN 1010, HW2
if all( (b.^2)-4.*(a).*(c)) >= 0 )
Num = -b +(plusOrMinus).* sqrt((b.^2)-(4.* a.* c));
denom = 2.*(a);
Root = Num./denom;
else
error(' the coeffecients yield a complex root')
end
However, it is not clear to me what plusOrMinus is and whether that will work with vectors or not. Maybe you could clarify what this is. Simply a +1 or -1 input?
1 comentario
khaled almutairi
el 15 de Feb. de 2017
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!