Two for loops taking very long to get the complete solutions

1 vue (au cours des 30 derniers jours)
AtoZ
AtoZ le 6 Nov 2018
Commenté : AtoZ le 7 Nov 2018
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 commentaires
Stephen23
Stephen23 le 6 Nov 2018
Modifié(e) : Stephen23 le 6 Nov 2018
"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 le 6 Nov 2018
Oh got it now. Thanks.

Connectez-vous pour commenter.

Réponse acceptée

madhan ravi
madhan ravi le 6 Nov 2018
Modifié(e) : madhan ravi le 6 Nov 2018
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 commentaires
madhan ravi
madhan ravi le 6 Nov 2018
+1 @Bruno brilliant stuff right there
AtoZ
AtoZ le 7 Nov 2018
@Bruno this is really nice. Thanks :-)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by