Clear Filters
Clear Filters

Two for loops taking very long to get the complete solutions

1 view (last 30 days)
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 Comments
Stephen23
Stephen23 on 6 Nov 2018
Edited: Stephen23 on 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?

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 6 Nov 2018
Edited: madhan ravi on 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 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!