Hi!

I would really appreciate if somebody could help me with my problem. I

have to calculate n-th eigenvalue of equation:

y'' = lambda * y

First I made a system of 4 equations:

then I found solution with RungeKutta method:

I have problems with Newton iteration. What to write in matlab.

Function:

Code:

f = inline('[-y(2); lam*y(1); -y(4); lam*y(3)+y(1)]','x','y','lam');

Here is my RK4:

Code:

function [x1, y1, spr, values] = RungeKutta4(f, x0, y0, xb, lam, N)
%[x1, y1, lam, spr, values] = RungeKutta4(f, x0, y0, xb, lam, N)
%y0 =[0 1 0 0]'
%lam = lambda
%N j=number of steps for RK4
%spr = number of changes: spr(++ ----++ - ++) = 4
values = [];
values(1)=y0(1);
h=(xb-x0)/N;
spr = 0;
for i = 1:N
k1 = h*feval(f, x0, y0, lam);
k2 = h*feval(f, x0+(h/2), y0+(k1/2),lam);
k3 = h*feval(f, x0+(h/2), y0+(k2/2),lam);
k4 = h*feval(f, x0+h, y0+k3,lam);
a=y0(1);
y0 = y0 + (k1 + 2*k2 + 2*k3 + k4)/6;
x0 = x0 + h;
values(i+1)=y0(1);
if sgn(a)~=sgn(y0(1))
spr = spr +1;
end
%hold on
%plot(x0,y0(1),'-x')
%plot(x0,y0(3),'-*')
end

I made also program for searching interval where n-th eigenvalue is:

Code:

function root = BISECTION(f,xa,y0,xb,lam,N,c,d,whichLambda)
root=(c+d)/2;
while (root~=c) & (root~=d)
if whichLambda>SIGN(f,xa,root,lam,N)
c=root;
else
d=root;
end
root=(c+d)/2;
end

SIGN counts number of sign changes in interval [xa, root]

And here is problem...newton iteration. My program:

Code:

function lam = fN(f, x0, y0, xb, lam, N, n)
%lam = fN(f, x0, y0, xb, lam, N, n)
%n = number of steps for Newton's iteration
%N = number of steps for RK4
lam1=16.1;
for i = 1:n
[x1, y1, spr, vr] = RungeKutta4(f, x0, y0, xb, lam, N);
lam1 = lam1 - (y1(1))/(y1(3));
end

I'm not getting any good results for eigenvalue (lam1).

Thanks for any help...

Igor