シンボリック代入(subs)の速さについて
Show older comments
以下のように、関数S1(t)をω積分で求めるために被積分関数の分母を因数分解し、部分分数分解をするプログラムを書きました。
S1(t)を求めたあと、subsを用いて新たにTを代入し、S2とするのですが代入の家庭で非常に時間がかかります。
時間を短縮する代入やり方や、因数分解・部分分数分解で短縮できるプロセスがあれば教えていただきたいです。
syms e w t
A=5;m=1;s=1;wA=1;c=10^-10;
%分母の関数を因数分解
eqn=w.^2+(-m-wA+(sqrt(2).*s+c)*1i).*w+(m-(sqrt(2).*s+c).*1i).*wA-sqrt(2).*A.*s==0;
sols=simplify(solve(eqn,w));
%部分分数分解
F=partfrac((w-m+(sqrt(2)+c)*1i)./((w-sols(1)).*(w-sols(2))),w,"FactorMode","full");
S1(t)=(1i./2*pi).*int(F*exp(-1i.*w.*t),w,-100,100);
T=0:0.10:10;
S2=subs(S1,t,T);
Answers (1)
matlabFunction をご使用ください
syms e w t
A=5;m=1;s=1;wA=1;c=10^-10;
%分母の関数を因数分解
eqn=w.^2+(-m-wA+(sqrt(2).*s+c)*1i).*w+(m-(sqrt(2).*s+c).*1i).*wA-sqrt(2).*A.*s==0;
sols=simplify(solve(eqn,w));
%部分分数分解
F=partfrac((w-m+(sqrt(2)+c)*1i)./((w-sols(1)).*(w-sols(2))),w,"FactorMode","full");
S1(t)=(1i./2*pi).*int(F*exp(-1i.*w.*t),w,-100,100);
T=0:0.10:1;
% tic
% S2=subs(S1,t,T);
% toc
F = matlabFunction(S1)
S3=zeros(length(T),1);
tic
for ii = 1:length(T)
S3(ii)= F(T(ii));
end
toc
S3
1 Comment
kazuma kaneda
on 4 Feb 2022
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!