Assigning roots as variables to a function

5 ビュー (過去 30 日間)
John Blaz
John Blaz 2020 年 12 月 30 日
コメント済み: John Blaz 2020 年 12 月 31 日
I have x^2+5*x+6=0.
I see the roots with the root command but i want to set them as variables to a new function. Also how can i set them to two different displays? I want to write down:
sprintf( 'the first root:%f and the second root:%f')

採用された回答

Pat Gipper
Pat Gipper 2020 年 12 月 31 日
The output of the roots function can be assigned to a workspace array variable and printed out as you wanted. See the simple example below. You would have to adapt the formatting for complex roots.
x=roots([1,5,6]);
sprintf('the first root:%f and the second root:%f',x)
  4 件のコメント
Pat Gipper
Pat Gipper 2020 年 12 月 31 日
You just need to swap variables y and x in the function assignment,
x1=y(1);
x2=y(2);
John Blaz
John Blaz 2020 年 12 月 31 日
It worked thank you.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by