Code covered by the BSD License

# Chebpack

### Damian Trif (view profile)

15 Jul 2011 (Updated )

The MATLAB package Chebpack solves specific problems for differential or integral equations.

[c,rez,drez,kod]=as(Nfun,lam,phi,phip,xleg,rleg,wleg,c0,m,errtol)
```function [c,rez,drez,kod]=as(Nfun,lam,phi,phip,xleg,rleg,wleg,c0,m,errtol)
%
% Calculates the coefficients c of the function associated to c0
%
[~,N]=size(phi);dc0=[eye(m);zeros(N-m,m)];drez=zeros(m,m);rez=zeros(m,1);
test=zeros(25,1);%dc=zeros(N,m);
for k=1:25
u=phi*c0;up=phip*c0;
du=phi*dc0;dup=phip*dc0;
[Nu,Npu,Npup]=feval(Nfun,xleg,u,up);% nonlinear part N
%Nucoef=x2t(Nu,kind);Npucoef=x2t(Npu,kind);Npupcoef=x2t(Npup,kind);
C=wip(phi,Nu,rleg,wleg);% iterations for u
c=[c0(1:m);C(m+1:N)./lam(m+1:N)];test(k)=norm(c-c0);
Cp=wip(phi,repmat(Npu,[1,m]).*du+...
repmat(Npup,[1,m]).*dup,rleg,wleg);% iterations for du
dc=[dc0(1:m,:);Cp(m+1:N,:)./repmat(lam(m+1:N),[1,m])];
test(k)=test(k)+norm(dc-dc0,1);
if test(k)<errtol, kod=k;break;end
%     if (k>3 && test(k)>test(k-1) && test(k-1)>test(k-2) &&...
%             test(k-2)>test(k-3)), kod=-2;return;end
c0=c;dc0=dc;
end
if k==25, kod=-1;return;end
rez=lam(1:m).*c0(1:m)-C(1:m);
drez=diag(lam(1:m)).*eye(m)-Cp(1:m,:);```