Negative squareroot quick and easy

2 次查看(过去 30 天)
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
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 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by