
%wykres na [0,1]
% f(x)(x-a)+a dla coraz wiekszych a - utrata dokladnosci 
x=linspace(0,1,1000);
p=1;a=5;
for p=2:24,
  a*=5;
  if(p>16)
  plot(x,(x-a)+a,[".;p=",num2str(p),";"]);pause(5);
  end
endfor


%w pojed. precyzji
x=linspace(0,1,1000);
p=single(1.0);a=single(5.0);
x=single(x);
for p=1:11,
  a*=5.0;
  if(p>3)
  plot(x,(x-a)+a,[".;p=",num2str(p),";"]);pause(3);
  end
endfor

%wykres (x-2)^4=x^4...+2^4 z obu wzorow
a=0.1;
for k=1:4,
  x=linspace(2-a,2+a,2000);
  w1=(x-2).*(x-2).*(x-2).*(x-2);
  w2=x.*x.*x.*x-4*2*x.*x.*x + 6*4*x.*x-4*8*x+16;
  plot(x,w1,x,w2,[";a=",num2str(a),";"]);pause(10);
  a*=0.1;
endfor


%w pojed. precyzji wykres (x-2)^4=x^4...+2^4 z obu wzorow
a=1.0;
for k=1:3,
  x=single(linspace(2-a,2+a,2000));
  w1=(x-2).*(x-2).*(x-2).*(x-2);
  w2=x.*x.*x.*x-4*2*x.*x.*x + 6*4*x.*x-4*8*x+16;
  plot(x,w1,x,w2,[";a=",num2str(a),";"]);pause(10);
  a*=0.1;
endfor

%f(x)=x-sqrt(1+x^2)=-1.0/(1+sqrt(1+x*x)) na 2 sposoby dla duzych x
x=[1,1e1,1e2,1e3,1e4,1e5,1e5,1e6,1e7,1e8,1e9,1e10]';
f1=@(x) x-sqrt(1+x.*x);
f2=@(x) -1.0./(x+sqrt(1+x.*x)); 
[x,y1=f1(x),y2=f2(x)]
bb=y2-y1
bz=bb./y2

%pojedyncza precyzja
x=single(x);
[z1=f1(x),z2=f2(x)]
bb=z2-z1
bz=bb./y2


#nasz exponent

function y=nexp(x,N=100)
  y=ones(size(x));xx=ones(size(x));
  for k=1:N,
    xx=(xx.*x)/k;
    y+=xx;
  endfor
endfunction
x=-100:10:100;x=x';
y1=nexp(x)
y2=exp(x)
bb=y1-y2;
bz=bb./y2;
[x,bb,bz]

function y=nexp1(x,N=100)
  z=(x>0);
  s=(x<=0);
  x=-x.*s+x.*z;
  y=ones(size(x));
  xx=ones(size(x));
  for k=1:N,
    xx=(xx.*x)/k;
    y+=xx;
  endfor
  y=y.*z+ (1./y).*s;
endfunction
x=-100:10:100;x=x';
y1=nexp1(x)
y2=exp(x)
bb=y1-y2;
bz=bb./y2;
[x,bb,bz]