Two for loops taking very long to get the complete solutions

1 回表示 (過去 30 日間)
AtoZ
AtoZ 2018 年 11 月 6 日
コメント済み: AtoZ 2018 年 11 月 7 日
The two for loops in the code take very long to complete
clear all
syms a
for k=0:0.1:pi
for x=0:0.1:pi
f = sin(k+a) - x*cos(x);
y=vpasolve(f,a,[0 pi])
end
end
How to fix this?
  4 件のコメント
Stephen23
Stephen23 2018 年 11 月 6 日
編集済み: Stephen23 2018 年 11 月 6 日
"I thought I was doing the solution numerically already. :-)"
Kind of, but you are finding a numeric solution using symbolic variables:
syms a
Symbolic maths is slow. Why not just write fast numeric code without symbolic variables?
AtoZ
AtoZ 2018 年 11 月 6 日
Oh got it now. Thanks.

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

採用された回答

madhan ravi
madhan ravi 2018 年 11 月 6 日
編集済み: madhan ravi 2018 年 11 月 6 日
EDITED
syms k a x
f = sin(k+a) - x*cos(x);
solution=solve(f,a)
x=0:0.1:pi;
k=x;
solutions=vpa(subs(solution),3)
  19 件のコメント
madhan ravi
madhan ravi 2018 年 11 月 6 日
+1 @Bruno brilliant stuff right there
AtoZ
AtoZ 2018 年 11 月 7 日
@Bruno this is really nice. Thanks :-)

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by