write the program to calculate real roots of quadradic equation with nested function.

3 ビュー (過去 30 日間)
hi,i I'm pretty new in matlab .i wanna write the program to calculate real roots of quadradic equation with nested function.
function[x1,x2]= quadratic(a,b,c)
d=0
disc;
function disc
d = sqrt(b^2-4*a*c);
end
disc;
x1 =(-b + d)/(2*a);
x2 =(-b - d)/(2*a);
end
Error:File: quadratic2.m Line: 6 Column: 11
Identifier 'd' is not a function or a shared variable. To share 'd' with nested function, initialize it in the current
scope. For more information, see Sharing Variables Between Parent and Nested Functions.
i have no idea what should i do...

採用された回答

Alan Stevens
Alan Stevens 2020 年 12 月 8 日
You are over complicating things! All you need is
function[x1,x2]= quadratic(a,b,c)
d = sqrt(b^2-4*a*c);
x1 =(-b + d)/(2*a);
x2 =(-b - d)/(2*a);
end
  1 件のコメント
ela mti
ela mti 2020 年 12 月 8 日
i know but this is my homework and they said i should use nested function for solve

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePattern Recognition and Classification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by