フィルターのクリア

How to tell Solve function to only display real roots?

3 ビュー (過去 30 日間)
lindsey Cameron
lindsey Cameron 2014 年 11 月 27 日
コメント済み: lindsey Cameron 2014 年 11 月 27 日
Hi guys,
Anyone know how I can restrict the Solve function in the current code to solve for only real values?
clear clc
syms x g
g=1.3099*10^15:0.05*10^15:2.6*10^15;
for i = 1:length(g) % Assigns i for each value within in g
f=(((1.1096*10^17-(5.201*10^16)*(6.667*(x - 255)/x)^(1/3))/(g(1,i))) + 255-x);
soln=solve(f,x);
end

採用された回答

Henrik
Henrik 2014 年 11 月 27 日
I don't know if this is what you want, but you could do something like
real_soln=soln(imag(soln)==0);
or if there are floating point errors,
real_soln=soln(abs(imag(soln))<1e-9); %put appropriate tolerance here
  1 件のコメント
lindsey Cameron
lindsey Cameron 2014 年 11 月 27 日
Great, thanks it worked!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by