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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by