Choose 1 real solution between 4 solutions

2 ビュー (過去 30 日間)
maze djenn
maze djenn 2021 年 5 月 17 日
コメント済み: Rik 2021 年 5 月 17 日
hello, i have a probleme of making Ma choose the right answer, the right solution is the 2nd one of x, y and z, is there any command to do that??

採用された回答

Rik
Rik 2021 年 5 月 17 日
You're using a syntax that is no longer valid in Matlab. Since you didn't specify your Matlab release (and posted your code as picture) I can't confirm the code below will work for you. It is also unclear to me why the first solution of you picture isn't a valid solution.
syms x
x=solve(x^3==1)
x = 
result=double(x);
L=abs(imag(result))<=eps;
correct_result=result(L);
correct_result
correct_result = 1
  2 件のコメント
maze djenn
maze djenn 2021 年 5 月 17 日
I use 2010 version. I choosed the 2nd question because it's the value that seems logic, im stimulating the heat transfert in solar heat collector and those solutions are the temperatures in Kelvin
Rik
Rik 2021 年 5 月 17 日
Then the code I showed you should solve your question.
Just a slight edit to L (and to the syntax for solve to account for your release):
syms x
x=solve('x^3=1');
result=double(x);
L= ... list all conditions here
abs(imag(result))<=eps & ...
real(result)>0;
correct_result=result(L);
correct_result
You should really mention it if you're using something older than a few years. R2010a and R2010b are not trivial to get to run on a modern operating system.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by