MATLAB Answers

why does my code take so long to run?

4 views (last 30 days)
Omar B.
Omar B. on 7 Oct 2020
Commented: Rena Berman on 12 Oct 2020
I am trying to compute v' * f(A) * v, where f is a given function, A matrix, and v is a unite vector.
My code takes along time doing run and did not get the result. Could please help me to fix this problem?
% want to compute v'*f(A)*v
syms f(x)
N=1000;
Ns=1:N;
R=1./(Ns);
A=sym(toeplitz(R));% the input matrix
v=ones(N,1);
v=v/norm(v);
f(x) = atan(sqrt(x)); % the function f(x)=arctan(sqrt(x))/x
B = funm(A,f); % the resulting matrix
y=A\v;
exact=v'*B*y
  5 Comments
Rena Berman
Rena Berman on 12 Oct 2020
(Answers Dev) Restored edit

Sign in to comment.

Answers (1)

Hiro
Hiro on 8 Oct 2020
It looks that your problem is not that complicated. Why don't you write your code without using symbolic expressions? I bet it is faster.
  3 Comments
Walter Roberson
Walter Roberson on 8 Oct 2020
Even for N=10 the symbolic version takes much much much too long.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!