quadratic calculator to display error messages

2 ビュー (過去 30 日間)
Mohamed Rashed
Mohamed Rashed 2021 年 3 月 8 日
回答済み: Monisha Nalluru 2021 年 3 月 11 日
hello i am trying to make a quadratic calculater that shows an error message or N/A when non solvable values are put in this is what i have so far but it dosent seem to be working how can i mend this?
vala = app.a.Value;
valb = app.b.Value;
valc = app.c.Value;
z1 =(-valb +sqrt(valb^2-4*vala*valc))/(2*vala);
z2 =(-valb -sqrt(valb^2-4*vala*valc))/(2*vala);
if z1 is double scalar;
app.x1.Value =z1;
else app.x1.Value ='N/A';
if z2 is double scalar
app.x2.Value =z2;
else app.x2.Value ='N/A';

回答 (1 件)

Monisha Nalluru
Monisha Nalluru 2021 年 3 月 11 日
From my understanding,
you want to display values when the roots are real and N/A in case of complex roots.
You can check whether the value is real using isreal() function
As an example
if (isreal(z1) & isreal(z2))
app.x1.value = z1;
app.x2.value = z2;
else
app.x1.value = 'N/A';
app.x2.value = 'N/A';
end

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by