×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Index exceeds matrix dimensions.

Index exceeds matrix dimensions.

Index exceeds matrix dimensions.

(OP)
Hi!

I need a help, I am a beginner in matlab programming and I am trying to write a function to compute associative legendre funtions by recursive relations. I am getting this error message

??? Index exceeds matrix dimensions.

Error in ==> D:\Matlab\Pmbar_nm.m
On line 28  ==>     Pbar(m) = u*sqrt((2*m+1)/(2*m))*Pbar(m-1,m-1);

I have typed the following code

function Pmbar_nm = Leg(phi,n_max,t)
%LEG copmutes the normalized associated legendre functions Pnm(t)by recurrence relation
if (nargin == 0)
   phi = -6;
   n_max = 18;
   lambda = 39;
   h = 0;
end;
%Initialize n_max
n_max = 180;

if n_max > 180, disp('Degree too large for the function, Upper summation bound too large!'), return, end;

GM = 3986004.418e8;     % m^3/s^2
a_e = 6378136.46;        % m
finv = 298.257223563;   % flatenning

% We input geodetic coordinates phi,lambda in degrees
% We have to transform the geodetic coordinates to geocentric coordinates in radians
[X,Y,Z] = frgeod(a_e,finv,phi,lambda,h);
[lambda,phi_geoc,r] = cart2sph(X,Y,Z); % lambda and phi_geoc are now in radians
t = sin(phi_geoc); % phi_geoc is geocentric latitude

% Pbar computes the normalized associated legendre function on the diagonal
Pbar =zeros(n_max+3,1);
for m = 2:n_max
     u= cos (phi_geoc)
    Pbar(m) = u*sqrt((2*m+1)/(2*m))*Pbar(m-1,m-1);
end

% Computing the normalisation coefficients a_nm and b_nm
a_nm = zeros((n_max+3)*(n_max+4)/2,1);
b_nm = a_nm;
for m = 1:n_max+1
    for n = m+1:n_max
        s = loc(n+1)+m;
        a_nm(s) = sqrt(((2*n+1)*(2*n-1))/((n-m)*(n+m)));
        b_nm(s) = sqrt(((2*n+1)*(n+m-1)*(n-m-1))/((2*n-3)*(n+m)*(n-m)));
    end
 end
q = a_e/r;
Pmbar(n-1,m) = zeros(n_max+4,1);
Pmbar(t)= Pmbar(n-1,m);
for n = 2:n_max
    for m = n_max:-1:2
        Pmbar(n-1,m) = Pbar(t)/u^m *10^(-280);
     end
      Pmbar(t)= a_nm*q*t*Pmbar(n-1,m)-b_nm*q^2*Pmbar(n-2,m);
  end
Pmbar(t)

I don't know what to do, please help me! thank you in advance.

dorodeus  

RE: Index exceeds matrix dimensions.

Pbar is defined as a 1D vector.

Pbar =zeros(n_max+3,1);

In line 28 you reference it as a 2D matrix

... *Pbar(m-1,m-1);

M

--
Dr Michael F Platten

RE: Index exceeds matrix dimensions.

(OP)
Hi Dr Michael,

Thank you very much for your quick respose to my question. let me try to correct my mistake. Thanks,

dorodeus

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources