Source

 Matlab 
Вычисление функции \mathrm{up}(x) через ряд по косинусам
функция
код
Код
 
function y = up_cos(t)
 %% initialization of F[up(x_k)] coefficients
 a = [0.500000000000000 ...
 0.553771275888810 ...
 -0.046202299134307 ...
 -0.008656867928610 ...
 0.001044808241827 ...
 -0.000356152861630 ...
 0.000298368336838 ...
 0.000091404980599 ...
 -0.000006555455731 ...
 -0.000003383844607 ...
 0.000012321122493];
 %% computation via Fouries cos series
 omega = pi;
 y = a(1) + a(2)*cos(omega*t) + a(3)*cos(3*omega*t) + ...
 a(4)*cos(5*omega*t) + a(5)*cos(7*omega*t) + a(6)*cos(9*omega*t) + ...
 a(7)*cos(11*omega*t) + a(8)*cos(13*omega*t) + a(9)*cos(15*omega*t);
 %% support is [-1,1]
 y(logical(abs(t)>1))=0;
 y(y<0)=0;
Описание: [pdf-en]
Вычисление функции \mathrm{up}(x) через ряд по Фурье
функция
код
Код
 
function y = sinc_(x) 
i=find(x==0); 
x(i)= 1; 
% From LS: don't need this is /0 warning is off 
y = sin(x)./(x); 
y(i) = 1; 
Код
 
function [F]=ft_up(t,n) 
% Fourier Transform of up(x)
Prom=1; 
for i=1:n, 
Prom=Prom.*sinc_(t/2^i); 
F=Prom; 
up
Код
 
function [F]=up(x,m,n) 
% Fourier Approximation 
% of up(x)
F = 0.0;
for i=1:m 
F = F + cos(pi*i*x)*ft_up(pi*i,n); 
end;
F = F + 0.5; 
%F(logical(abs(x)>1))=0; 
%F(F<0)=0;
Код
 
% test_up 
clc; clear all; close all;
t = -1:.01:1; 
x = up(t,20,20); 
figure('color','w'); 
plot(t,x)
Код
 
function [F]=ft_ha(a,t,n) 
% Определим ПФ от АФ ha(x) следующим образом 
% a - основание функции 
% t - аргумент 
% n - кол-во слагаемых в произведении
Prom=1; 
for i=1:n, 
Prom=Prom.*sinc_(t/a^i); 
end 
F=Prom;
ha
Код
 
function [F]=ha(x,a,m,n) 
% В этой функции реализуем атомарную функцию ha(x) используя разложение АФ 
% в быстросходящийся ряд Фурье 
% a - основание функции 
% m - количество слагаемых в ряде Фурье по косинусам 
% n - количество слагаемых в произведении (преобразовании фурье от up)
F = 0.0;
for i=1:m 
F = F + cos((a-1)*pi*i*x)*ft_ha(a,(a-1)*pi*i,n); 
end;
F = (a - 1)*(F + 0.5); 
F(logical(abs(x)>1/(a-1)))=0; 
F(F<0)=0;
Код
 
% test clc; clear all;close all;
a = 4;
t = -1/(a-1)+eps:.001:1/(a-1)+eps;
x2 = ha(t,a,10,2); 
x3 = ha(t,a,10,3); 
x4 = ha(t,a,10,4); 
x5 = ha(t,a,10,5); 
x6 = ha(t,a,10,6); 
x7 = ha(t,a,10,7); 
x8 = ha(t,a,10,8);

figure('color','w'); 
plot(t,x2,t,x3,t,x4,t,x5,t,x6,t,x7,t,x8);
xlabel('x'); 
ylabel(['h_{' int2str(a) '}(x)']); 
title(['atomic function h_{' int2str(a) '}(x)']); 
legend('n = 2','n = 3','n = 4','n = 5','n = 6','n = 7','n = 8'); 
saveas(gcf,'ha','png'); 
e2 = max((x3 - x2).^2); 
e3 = max((x4 - x3).^2); 
e4 = max((x5 - x4).^2); 
e5 = max((x6 - x5).^2); 
e6 = max((x7 - x6).^2); 
e7 = max((x8 - x7).^2); 
e = [e2 e3 e4 e5 e6 e7]; 

figure('color','w'); 
plot([3 4 5 6 7 8],e,'-ro'); 
xlabel('m'); 
ylabel('error'); 
title('rms error'); 
saveas(gcf,'rms_error_ha','png'); 

figure('color','w'); 
plot([4 5 6 7 8],[e3 e4 e5 e6 e7],'-ro'); 
xlabel('m'); 
ylabel('error'); 
title('rms error'); 
saveas(gcf,'rms_error__ha_2','png'); 

figure('color','w'); 
plot(t,x4); 
Добавление вейвлетов в Matlab
функция
код
Код
 
%% plot uplet % test 
close all; clc; clear

%% Add new family of wavelets 
wavemngr('restore',0) 
wavemngr('add','Atomic','up',3,'','uplet',[0,1])
%% Load uplet from Matlab Wavelet Toolbox 
[phi,psi,t] = wavefun('up');
%% Plot scaling function and wavelet (1st derivative) 
figure('color','w'), 
plot(t,phi, t,psi, 'LineWidth',2) 
xlabel('t'), ylabel('up'), title('uplet') 
legend('scaling function','wavelet')
Описание: [pdf-ru]
 C 
Вычисление \mathrm{up}(x) через последовательность Морса-Туэ
функция
код
Код
#include 
#include 
#include 
void main() 
{ 
int i,j,*a,n,dvaVn,dvaVi,max,a0,k; double x,z; 
//printf("Ведите n"); 
scanf("%d",&n); 
dvaVn=pow(2,n); 
dvaVi=dvaVn/2; 
a=malloc((n+1)*sizeof(int));
max=((n-2)*(n-1))/2; 
max=pow(2,max); 
for(i=0;i<n+1;i++) 
a[i]=0;for(i=0;i<n/2;i++) 
{ 
x=i; 
printf("%lf %lf\n",(x/dvaVi-1),0); 
} dvaVn=dvaVn-n/2; 

for(i=0;i<dvaVn;i++) 
{ 
a0=0; 
k=i; 
for(j=0;j<n;j++) 
{ 
a0=a0+k%2; k=k/2; 
} 
a0=1-2*(a0%2); 
a[0]=a0; 
for(j=1;j<n+1;j++) 
a[j]=a[j]+a[j-1]; 
//printf(" %d",a[n]); 
x=n/2+i; z=a[n]; 
printf("%lf %lf\n",(x/dvaVi-1),(z/max)); 
}/* 
for(i=0;i<j;i++) 
{ 
z=a[i]; 
x=i+n; 
// printf("%lf %lf\n",(x/dvaVi-1),(z/max)); 
}*/ 
}
Описание: [pdf-ru] [up_small.tex]
Вычисление \mathrm{up}(x) через ряд специального вида
функция
код
Код
#include
#include
#include

void binom(int n, int* a);
void raspechatkaint(int n, int* a);
void raspechatkadouble(int n, double* a);
void init_c(int n, double* c);
void init_a(int n, double* a, double* c);
void init_b(int n, double* b, double* a, int* binomials);
int faktorial(int n);
void morse(int n, int* a);
double up(double x,int n, double* b);

void main()
{
double x,*b,y,h;
int *binomials,n,i,j;
n=20;

b=malloc(2*n*sizeof(double));
binomials=malloc((n+3)*sizeof(int));

init_c(n/2,b);
init_a(n/2,b,b);
init_b(n/2,b,b,binomials);

x=-1;
//x=x+0.0000001;
//h=0.0007;
//h=0.25;
//h=0.125;
h=0.0625;
h=0.0007;
h=0.0005;
for(i=0;x<1;i++)
  {
  y=up(x,n,b);
  printf("%lf %lf\n",x,y);
  x=x+h;
  }
}

double up(double x,int n, double* b)
{
double y,bb,bbb,xx,xxx;
int j,k,s;
x=fabs(x);
xx=x;
y=1;

s=1;
for(k=1;k=1)
    {
    xx=xx-1;
    xxx=1;
    for(j=0;j1;i--)
  p=p*i;
return(p);
}

void init_a(int n, double* a, double* c)
{
int i;
double aa;
a[0]=1;
for(i=1;i0;n--)
  {
  for(i=0;i
Описание: [pdf-ru]
Skip to toolbar