Not sure how to implement specific part of Pade' Algorithm in MATLAB????

5 views (last 30 days)
Hello,
I am implementing the Pade' algorithm in MATLAB as is specified in the book Numerical Analysis (Burden) 9th edition (heres link http://ins.sjtu.edu.cn/people/mtang/textbook.pdf) book page 531, but I am not sure how to write the code for Step 12:
Step 12 Let k be the smallest integer with i ≤ k ≤ N and bk,i = maxi≤j≤N bj,i.
(Find pivot element.)
This is all my code for the Pade Algorithm so far, help would be appreciated Thanks.
if true
%Determine the Padé approximation of degree 6 with n = m = 3 for f (x) = sin x.
%Compare the results at xi = 0.1i, for i = 0, 1, . . . , 5,
%with the exact results and with the results of the sixth Maclaurin polynomial.
%Step 1
n = 3;
m = 3;
N = m + n;
%Step 2 skip
A = [0,1,0,-1/6,0,1/120];
%A = ones(1,6);
%Step 3
Q = ones(1,4);
P = ones(1,4);
Q(1,1) = 1;
P(1,1) = A(1,1);
%Step 4
B = ones(N,N);
for i = 1:N
%Step 5
for j = 1:i-1
if j <= n
B(i,j) = 0;
end
end
%Step 6
if i <= n
B(i,j) = 1;
end
%Step 7
temp1 = 1;
for j = i + temp1:N
temp1 = temp1 + 1;
B(i,j) = 0;
end
%Step 8
for j=1:i
if j <= m
temp2 = i-j;
if temp2==0 %this is not actually right
temp2 = 1;
end
B(i,n+j) = -1*A(1,temp2);
end
end
%Step 9
temp3 = 1;
for j=n+i+temp3:N
temp3 = temp3 + 1;
B(i,j) = 0;
end
%Step 10
B(i,N+1) = A(1,i);
end
%Step 11
temp4 = 1;
for i = n + temp4:N-1
temp4 = temp4 + 1;
for
for k=i:N
k=min(
%Step 13
if B(k,i)==0
Display('The system is singular');
break;
end
%Step 14
if k ~= i
temp5 = 0;
for j=i+temp5:N+1
temp5 = temp5 + 1;
temp6 = B(i,j);
B(i,j) = B(k,j);
B(k,j) = temp6;
end
end
%Step 15
temp7 = 1;
for j=i+temp7:N
temp7 = temp7 + 1;
%Step 16
xm = B(j,i) / B(i,i);
%Step 17
temp8 = 1;
for k=i+temp8:N+1
B(j,k) = B(j,k) - xm * B(i,k); %not sure about this
end
%Step 18
B(j,i) = 0;
end
end
%Step 19
if B(N,N) == 0
Display('The system is singular!');
break;
end
%Step 20
if m>0
Q(1,m) = B(N,N+1) / B(N,N);
end
%Step 21
temp9 = 1;
for i=N-temp9:n+1
temp9 = temp9 + 1;
Q(1,i-n) = (B(i,N+1) - shit) / (B(i,j)); %shit
end
%Step 22
temp10 = 0;
for i=n-temp10:1
temp10 = temp10 + 1;
P(1,i) = B(i,N+1) - shit; %shit
end
%Step 23
Display('P is');
Display(P);
Display('Q is');
Display(Q);
%DONE
end

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!