MATLAB Answers

why does my code take so long to run?

2 ビュー (過去 30 日間)
Omar B.
Omar B. 2020 年 10 月 7 日
コメント済み: Rena Berman 2020 年 10 月 12 日
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 件のコメント
Rena Berman
Rena Berman 2020 年 10 月 12 日
(Answers Dev) Restored edit

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

回答 (1 件)

Hiro
Hiro 2020 年 10 月 8 日
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 件のコメント
Walter Roberson
Walter Roberson 2020 年 10 月 8 日
Even for N=10 the symbolic version takes much much much too long.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by