Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index exceeds matrix dimensions.

Status
Not open for further replies.

dorodeus78

Computer
Apr 21, 2006
3
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

 
Replies continue below

Recommended for you

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
 
Hi Dr Michael,

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

dorodeus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor