# How can I draw graphs of P_n(x) function?

Graphs of iterated functions in Weierstrass’s approximation theorem

I have a problem while drawing the following functions: Here is my code:

import graph;
size(8cm,6cm,false);

real F(real x){return sin(x)*sin(pi*x);}

typedef real integral(real);

integral G(int n){return new real(real x){
return ((1-x^2)^n)/(simpson(new real(real t){return (1-t^2)^n;},-1,1));}; }

integral Pnx(int n){return new real(real x){ // I think it is right!
return simpson(new real(real t){return F(t)*G(n)(t-x);},0,1);}; }

draw(Label("$x$",EndPoint),(-2,0)--(2,0),Arrow);
draw(Label("$y$",EndPoint),(0,-2)--(0,4),Arrow);
int smooth=400;
path f=graph(F,0,1,smooth);
draw(f,brown);

pen pe[]={red,green,blue,cyan,magenta,pink,gray};
pe.cyclic=true;
path g;
for (int i : new int[]{5,10,15,20,25,30,35}){
g=graph(G(i),-1,1,smooth);
draw(g,pe[i]);
}

// path h=graph(Pnx(5),0,1,smooth); // can't draw
// draw(h,blue); // can't draw


The output: Question:

Is my computer weak to draw this function?

TeX - LaTeX Asked on November 21, 2021

Try this one:

settings.tex="pdflatex";
import math;
import graph;
size(8cm,6cm,false);
real sc=0.05;
real xmin=0,xmax=1;
real ymin=0,ymax=0.5;
xaxis(xmin,xmax,RightTicks(Step=0.2,step=0.1),above=true);
yaxis(ymin,ymax,LeftTicks (Step=0.1,step=0.05),above=true);

real F(real x){return sin(x)*sin(pi*x);}
typedef real realFreal(real);
real sqrtPi=sqrt(pi);
realFreal Q(int n){ // int((1-t^2)^n,t=-1..1)
//   = sqrt(pi)*gamma(n+1)/gamma(n+3/2)
return
new real(real x){
return (1-x^2)^n*gamma(n+3/2)/gamma(n+1)/sqrtPi;
};
}
realFreal FPn(int n, real x){
real c=gamma(n+3/2)/gamma(n+1)/sqrt(pi);
return new real(real t){return c*sin(t)*sin(pi*t)*(1-(t-x)^2)^n;};
}
realFreal Pn(int n){
return new real(real x){return simpson(FPn(n,x),0,1);};
}

int smooth=400;
pen pe[]={red,green,blue,cyan,magenta,pink,gray}; pe.cyclic=true;

path g;
for (int ni : new int[]{5,10,15,20,25,30,35}){
g=graph(Pn(ni),0,1,smooth);
draw(g,pe[ni]);
} Answered by g.kov on November 21, 2021

## Related Questions

### Automatically enlarging slides for easier readability

0  Asked on December 1, 2020 by s-olafsson

### Automatic choice of curly and straight extensible braces in MTPro2

0  Asked on December 1, 2020 by paulo-ney

### EDAS upload fail: IEEEtran sidemargins_a4 error

1  Asked on December 1, 2020 by paulgavrikov

### Redefinition of equation* break the [ … ], why?

1  Asked on December 1, 2020 by jinwen

### Is there an easy way to encapsulate a tikz drawing using “plot” commands as part of a node style?

0  Asked on December 1, 2020 by jason-s

### autoref with subfiles in TexStudio

1  Asked on December 1, 2020 by marvin-dippell

### Column headings on the table border

2  Asked on November 30, 2020

### How to get only one symbol from a symbol package?

4  Asked on November 30, 2020 by colas

### Define a command on xelatex command line

1  Asked on November 30, 2020

### What does this warning mean? (fancyhdr and headheight)

1  Asked on November 30, 2020 by josinalvo

1  Asked on November 30, 2020

### Using bigtriangledown as the nabla operator: vertical adjustment

2  Asked on November 30, 2020 by aspvl

### Space between headers and title Content in ToC

2  Asked on November 30, 2020 by sharpcfc

### How can I arrange my plots using subfloat?

1  Asked on November 30, 2020

### Plotted function overlaid by the gridlines

1  Asked on November 30, 2020

### Ignoring parentheticals in LawTeX citations

1  Asked on November 30, 2020 by pat-w

### key_define option

1  Asked on November 30, 2020 by azetina

### Omitting drawing a part of the outline of a drawing

1  Asked on November 30, 2020 by hany

### Inserting Curly Brackets in equations

1  Asked on November 30, 2020

### distance between formula and note

2  Asked on November 30, 2020