-1

I have an equation which includes continued fraction. I want to find particular root of this equation for all R which is a parameter of the equation.

For this I:

  • input this continued fraction as a polynomial expression into MATLAB
  • simplify this polynomium
  • compute all roots of the expression
  • and finally search the root that I'm interested in.

The problem I have is that higher R needs higher accuracy so more level of continued fraction, but my computer can not compute that much(I have i7 3rd gen 12gb ram laptop 2 cores).

Is there any chance to use parallel computing or GPU computing to compute this equation? Can optimize my code? Or use other computing programs to compute these roots.

    %%
clear; close all; clc;
%%
syms R;
Z=1; E=1; P1=sqrt(2*E);
m=0;
c=m+1; d=c; a=-1i*Z/P1+m+1; t=-2*1i*P1*R;
n=20;
%A, B, C koeficientebis gansazgvra
for k=0:n
    A(k+1)=(k+1)*(k+c);
    B(k+1)=-k*( k-1+t+c+d );
    C(k+1)=t*(k-1+a);
end
syms x;
for i=1:n
    P(i)=x;
    Q(i)=x;
end
% gantolebis chawera
for k=1:n-2
    if k==1
        P(k)=(-C(k+1));
        Q(k)=(B(k+1)-x);
    elseif k==2
        P(k)=-C(k)*(B(k+1)-x);
        Q(k)=(B(k)-x)*(B(k+1)-x)+(-A(k)*C(k+1));
    else
    P(k)=(B(k+1)-x)*P(k-1)+(-A(k)*C(k+1))*P(k-2);
    Q(k)=(B(k+1)-x)*Q(k-1)+(-A(k)*C(k+1))*Q(k-2);
    end
end
    eqn(x)=-x*Q(n-2)+P(n-2);
    eqn=simplify(eqn);
    eqn(R)=eqn;
    R=0.1:0.1:9;
    R=double(R);
    eqn=eqn(R);  
    ros(:,1)=R;
    for i=1:length(R)
        coef(i,:)=flip(double(coeffs(eqn(i))));
        ros(i,2:n)=roots(coef(i,:));
    end
for i=0:n-1
   plot(R,real(ros(:,n-i)),R,imag(ros(:,n-i)));hold on;
end

My computer can compute when n=35 maximum and it need a little bit much time. But I need like n to be 50-60.

EDIT: The problem seems to be ram usage during:

eqn=simplify(eqn);
Solstad
  • 285
  • 1
  • 9
tsogam
  • 51
  • 1
  • 12
  • What is the point of the symbolic math here? – Bernhard Dec 06 '16 at 12:39
  • Function `roots()` takes polynomial coefficients to compute roots, my equation needed simplification for that, that's why I used symbolic expression. I tried `solve()` but it gives me root of something and I need numbers. – tsogam Dec 06 '16 at 16:31

1 Answers1

0

Try optimizing your code by avoiding loops, when possible. For instance A, B and C do not depend on each other in:

%A, B, C koeficientebis gansazgvra
for k=0:n
    A(k+1)=(k+1)*(k+c);
    B(k+1)=-k*( k-1+t+c+d );
    C(k+1)=t*(k-1+a);
end

Thus you can write it as:

k=0:n;
A(k+1)=(k+1).*(k+c);
B(k+1)=-k.*( k-1+t+c+d );
C(k+1)=t.*(k-1+a);

Note that I have added dots at multiplications (.*) to avoid matrix multiplications.

Solstad
  • 285
  • 1
  • 9
  • Thanks for responding, but my main problem is in simplifying the equation when `n` is big it takes big time and my ram is not enough for it. – tsogam Dec 06 '16 at 16:38
  • So "eqn=simplify(eqn);" is the problem? Then try simplifying earlier in the code, and then simplifying again in the end. – Solstad Dec 07 '16 at 11:48