

#single i eps

eps
1+eps>1
1+0.5*eps>1

1+single(10*eps)>1

#k : 2^{-k}+1>1 a 2^{-k-1}+1==1 w fl

k=0;
a=1;
while(a+1>1)
 a*=0.5;
 k++;
end
k-a
2*a
eps
2*a-eps

#wykres (x+a)-a dla a duzych
t=linspace(0,1);
a=25;
for k=3:30,
 plot(t,(t+a)-a);
 a*=5;
 pause(0.5);
endfor


#wykresy (x-2)^4 na 2 sposoby

f1=@(x) (x-2).*(x-2).*(x-2).*(x-2)
f2=@(x) x.*x.*x.*x - 8*x.*x.*x+24.*x.*x-32*x+16;

e=0.01;
for k=1:3,
 t=linspace(2-e,2+e);e*=0.1;
 plot(t,f1(t),t,f2(t),";f2;");pause(1);
end

#f(x)=x-sqrt(1+x.*x) =-1/(1+sqrt(1+x.*x))
#na 2 sposoby

f1=@(x) x-sqrt(1+x.*x) 
f2=@(x) -1.0./(x+sqrt(1+x.*x))

k=1:20;
x=10.^k
y1=f1(x);
y2=f2(x);
bb=abs(y1-y2)
bw=bb./abs(y2)

#nasz exponent z rozwiniecia w szereg

function y=nexp(x,N=500)
 y=c=1;
 for k=1:N,
  c=c.*x/k;
  y=y+c;
 endfor
endfunction

k=1:5;
x=2.^k;
#dla dodatnich x
y1=exp(x);
y2=nexp(x);
bb=abs(y1-y2)
max(bb)
bw=bb./y1
max(bw)

#to samo ale dla N=500;
y2=nexp(x,5000);

bb=abs(y1-y2)
max(bb)
bw=bb./y1
max(bw)
#dla duzych N lepiej


#dla ujemnych x
x=-x;
y1=exp(x);
y2=nexp(x,500);
bb1=abs(y1-y2);
max(bb1)
bw1=bb1./y1
max(bw1)
#poprawiamy nexp dla x<0 
function y=nexp1(x,N=500)
if(x<0)
 y=1.0./nexp(-x);
else 
 y=nexp(x);
endif
endfunction

y1=exp(x);
y2=nexp1(x,500);
bb2=abs(y1-y2);
max(bb2)
bw2=bb2./y1
max(bw2)
#porownajmy
[bw2;bw1]


















