how do i make this function accept vector values ?
古いコメントを表示
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
回答 (1 件)
James Tursa
2017 年 2 月 15 日
編集済み: James Tursa
2017 年 2 月 15 日
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?
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!