Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:03:57+00:00 2026-06-08T18:03:57+00:00

I converted a written code in fortran 77 to Matlab code. This function computes

  • 0

I converted a written code in fortran 77 to Matlab code. This function computes the eigenvalues and eigenvectors of a matrix using QL algorithm. for some reasons I can’t use the eig function’s result in matlab. The obtained eigenvalues from this method is not identical to those obtained by eig function, some of them are the same but some differs. I don’t know where is the problem. Thank you for any help and suggestion. I can give the input arrays, if needed for running and watching the results.

here is the fortran code:

      SUBROUTINE tqli(d,e,n,np,z)
      INTEGER n,np
      REAL d(np),e(np),z(np,np)
CU    USES pythag
      INTEGER i,iter,k,l,m
      REAL b,c,dd,f,g,p,r,s,pythag
      do 11 i=2,n
        e(i-1)=e(i)
11    continue
      e(n)=0.
      do 15 l=1,n
        iter=0
1       do 12 m=l,n-1
          dd=abs(d(m))+abs(d(m+1))
          if (abs(e(m))+dd.eq.dd) goto 2
12      continue
        m=n
2       if(m.ne.l)then
          if(iter.eq.30)pause 'too many iterations in tqli'
          iter=iter+1
          g=(d(l+1)-d(l))/(2.*e(l))
          r=pythag(g,1.)
          g=d(m)-d(l)+e(l)/(g+sign(r,g))
          s=1.
          c=1.
          p=0.
          do 14 i=m-1,l,-1
            f=s*e(i)
            b=c*e(i)
            r=pythag(f,g)
            e(i+1)=r
            if(r.eq.0.)then
              d(i+1)=d(i+1)-p
              e(m)=0.
              goto 1
            endif
            s=f/r
            c=g/r
            g=d(i+1)-p
            r=(d(i)-g)*s+2.*c*b
            p=s*r
            d(i+1)=g+p
            g=c*r-b
C     Omit lines from here ...
            do 13 k=1,n
              f=z(k,i+1)
              z(k,i+1)=s*z(k,i)+c*f
              z(k,i)=c*z(k,i)-s*f
13          continue
C     ... to here when finding only eigenvalues.
14        continue
          d(l)=d(l)-p
          e(l)=g
          e(m)=0.
          goto 1
        endif
15    continue
      return
      END

and the following is the matlab code:

function [d,z]=tqli(d,e,n,np,z)

for i=2:n
    e(i-1)=e(i);
end
e(n)=0.;
for l=1:n
    iter=0;
    for m=l:(n-1)
        dd=abs(d(m))+abs(d(m+1));
        if ((abs(e(m))+dd)==dd)
            break
        end
    end
    m=n;
    if (m~=l)
        if (iter==30)
            disp('too many iteration in tqli')
        end
        iter=iter+1;
        g=(d(l+1)-d(l))/(2.*e(l));
        r=pythag(g,1.);
        g=d(m)-d(l)+e(l)/(g+r*sign(g));
        s=1.;
        c=1.;
        p=0.;
        for i=(m-1):-1:l
            f=s*e(i);
            b=c*e(i);
            r=pythag(f,g);
            e(i+1)=r;
            if(r==0.)
                d(i+1)=d(i+1)-p;
                e(m)=0.;
                break
            end
            s=f/r;
            c=g/r;
            g=d(i+1)-p;
            r=(d(i)-g)*s+2.*c*b;
            p=s*r;
            d(i+1)=g+p;
            g=c*r-b;
            for k=1:n
                f=z(k,i+1);
                z(k,i+1)=s*z(k,i)+c*f;
                z(k,i)=c*z(k,i)-s*f;
            end
        end
        d(l)=d(l)-p;
        e(l)=g;
        e(m)=0.;
    end
end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:04:01+00:00Added an answer on June 8, 2026 at 6:04 pm

    I saw a couple of things that may cause trouble with your matlab translation. One was your conversion of the fortran sign. You need to use abs(r) instead of just r.

    The other more serious problem I saw was your flow structure resulting from your trying to refactor the goto’s. When I converted this with f2matlab (and an unreleased tool that I wrote, remgoto) it came up with the following flow structure. I hope this helps you on your way. Note this is all untested!

    function [d,e,n,np,z]=tqli(d,e,n,np,z);
    
    remg([1:2])=true;
    
    for i = 2 : n;
     e(i-1) = e(i);
    end
    e(n) = 0.;
    for l = 1 : n;
     while (1);
      if(remg(2))
       if(remg(1))
        iter = 0;
       end;
       remg(1)=true;
       for m = l : n - 1;
        dd = abs(d(m)) + abs(d(m+1));
        if( abs(e(m))+dd==dd )
         remg(2)=false;
         break;
        end;
       end;
       if(~(remg(2)))
        continue;
       end;
       m = fix(n);
      end;
      remg(2)=true;
      if( m~=l )
       if( iter==30 )
        disp(['too many iterations in tqli',' -- Hit Return to continue']);
        pause ;
       end;
       iter = fix(iter + 1);
       g =(d(l+1)-d(l))./(2..*e(l));
       r = pythag(g,1.);
       g = d(m) - d(l) + e(l)./(g+(abs(r).*sign(g)));
       s = 1.;
       c = 1.;
       p = 0.;
       for i = m - 1 : -1: l ;
        f = s.*e(i);
        b = c.*e(i);
        r = pythag(f,g);
        e(i+1) = r;
        if( r==0. )
         d(i+1) = d(i+1) - p;
         e(m) = 0.;
         remg(1)=false;
         break;
        end;
        s = f./r;
        c = g./r;
        g = d(i+1) - p;
        r =(d(i)-g).*s + 2..*c.*b;
        p = s.*r;
        d(i+1) = g + p;
        g = c.*r - b;
        %        Omit lines from here ...
        for k = 1 : n;
         f = z(k,i+1);
         z(k,i+1) = s.*z(k,i) + c.*f;
         z(k,i) = c.*z(k,i) - s.*f;
        end; k = fix(n+1);
        %        ... to here when finding only eigenvalues.
       end;
       if(~(remg(1)))
        continue;
       end;
       d(l) = d(l) - p;
       e(l) = g;
       e(m) = 0.;
       remg(1)=false;
       continue;
      end;
      break;
     end;
    end;
    end %subroutine tqli
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've converted a code written in Python 2.6 into Python 3 using 2to3. All
I've written some code to parse the Google Distance Matrix JSON response received by
I have written this code to convert string in such format 0(532) 222 22
I've converted an api written in Java into a .net dll using IKVM, and
I'm trying to write my own code for a 'friends-of-friends' algorithm. This algorithm acts
this sp was written for SQL Server and then 'converted ' for use in
A have a lot of code written in FORTRAN 77. I want start developing
So I've written some code in Ruby to split a text file up into
I've written some simple code which interfaces with HandbrakeCLI to convert a video into
I have a COM component written in C++ that has a Print function. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.