Negative squareroot quick and easy

I just need a quick and easy way to say The square root of xxxx is yyyyi so the square root of -100 is etc...
B = sqrt® ;
disp(B);
D = sprintf('R is negative. The square root of %1.1f is %1.1fi',R,B)
For some reason it says B is 0 for any number thats negative.

 採用された回答

Robert
Robert 2016 年 3 月 10 日

0 投票

sprint is taking the real part of your complex result. Try:
sprintf('R is negative. The square root of %1.1f is %1.1fi',R,imag(B))

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFunction Creation についてさらに検索

タグ

質問済み:

2016 年 3 月 10 日

回答済み:

2016 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by