Writing a one line programme to show that an equation equals to the answer shown.

1 回表示 (過去 30 日間)
NIMA RAHMANI MEHDIABADI
NIMA RAHMANI MEHDIABADI 2019 年 3 月 19 日
回答済み: John D'Errico 2019 年 3 月 19 日
How can i write a one line programme to show that sqrt(4) = 2 .
solve('sqrt(4)')
it says :
Error using solve>getEqns (line 418)
List of equations must not be empty.
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});

回答 (1 件)

John D'Errico
John D'Errico 2019 年 3 月 19 日
Homework, but you did make an effort. Does this not show what you need to show?
sqrt(4)
ans =
2
Or this?
sqrt(4) == 2
ans =
logical
1
You were asked to show that statement to be true. Not to solve for the square root. Were you to try to do that, then you should arguably get BOTH branches of the square root. In one line, perhaps this...
solve(str2sym('x^2==4'))
ans =
-2
2
But I will argue that is not what was requested.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by