using a vector to represent three coefficients.

6 ビュー (過去 30 日間)
William McLaughlin
William McLaughlin 2020 年 1 月 20 日
回答済み: KSSV 2020 年 1 月 20 日
Hello I was hoping a could get a reality check on a simple code I wrote that was working the other day. I don't know if I'm just fat fingering something now or if it's bugged somewhere but I was able to input a vector and such as [1 2 3] and it would automatically replace [a b c].
function [quadRoots,disc] = Q1_19000046(coeff)
%[quadRoots,disc] = Q1_19000046(coeff);
%Compute quadRoots and disc of quadratic equation for parameters a, b, and
%c
coeff = [a b c];
X = sqrt(b .^2 - 4 .*a .*c);
Y = 2*a;
quadRoots = (-b + X) ./ Y;
disc = (-b - X) ./ Y;
end
  1 件のコメント
Sindar
Sindar 2020 年 1 月 20 日
I would expect this to throw an error (a,b,c undefined). I'm not sure what might have changed since it was working.
If you want [a b c] from coeff:
a = coeff(1);
b = coeff(2);
c = coeff(3);

サインインしてコメントする。

採用された回答

KSSV
KSSV 2020 年 1 月 20 日
function [quadRoots,disc] = Q1_19000046(coeff)
%[quadRoots,disc] = Q1_19000046(coeff);
%Compute quadRoots and disc of quadratic equation for parameters a, b, and
%c
a = coeff(1);
b = coeff(2);
c = coeff(3);
X = sqrt(b .^2 - 4 .*a .*c);
Y = 2*a;
quadRoots = (-b + X) ./ Y;
disc = (-b - X) ./ Y;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by