Sponsored links: Algebra eBooks
 

Related

while

y:1;

while (y<5) do y...

y;

Calculate

while

y:1;

while (y<5) do y...

y: y*2;

Calculate

while

y:1;

while (y<5) do y...

Calculate

while

y:1;

while (y<5) do y...

y;

Calculate

while

y:1;

while (y<5) do y...

y: y*2;

Calculate

while

y:1;

while (y<5) do y...

Calculate

while

Run Example
(%i1)numer:true;
(%o1)                                true
(%i2) ln(x):=log(x)/log(%e);
                                        log(x)
(%o2)                          ln(x) := -------
                                        log(%e)
(%i3) redondeo(num,decimales):=block(       [a:0],   a:round(num*10^decimales)*10^-decimales,    return(a));
(%o3) redondeo(num, decimales) := block([a : 0], 
                                           decimales    - decimales
                          a : 'round(num 10         ) 10           , return(a))
(%i4) biseccion(a,b,expo,N):=block(       [indice:0,bool:true,fa,fp,fb,fafp,TOL,p,er,tabla:matrix(['N,'a,'b,'p,'f('a),'f('b),'f('p),'f('a)*'f('p),'error])],      fa:f(a),   fa:redondeo(fa,expo+2),   TOL:(10)^(-expo),   for i:1 step 1 while (i<
=N and bool=true) do   (      indice:i,      p:((a+b)/2),         p:redondeo(p,expo+2),      fp:f(p),         fp:redondeo(fp,expo+2),      fb:f(b),         fb:redondeo(fb,expo+2),      er:((b-a)/2),         er:redondeo(er,expo+2),      fafp:redondeo(fa*fp,expo+2),            if ( (fa<
0 and fb<
0) or (fa>
0 and fb>
0) ) then      (	           print("No hay cambio de signo"),	 bool:false      ),      tabla:addrow(tabla,[i,a,b,p,fa,fb,fp,fafp,er]),            if ((fp=0) or (er <
 TOL)) then      (         print("tolerancia cumplida"),	 bool:false      )      elseif (fafp>
0) then      (         a:p,         fa:fp      )      else      (         b:p      )   ),      if (indice=N) then    (      print(concat("Parametro N=",N," se cumplio. Hay cambios de signo f(a) f(b)")),      print("en las iteraciones hechas.")   ),   display(indice,N),   return(tabla));
(%o4) biseccion(a, b, expo, N) := block([indice : 0, bool : true, fa, fp, fb, 
fafp, TOL, p, er, tabla : matrix(['N, 'a, 'b, 'p, 'f('a), 'f('b), 'f('p), 
'f('a) 'f('p), 'error])], fa : f(a), fa : redondeo(fa, expo + 2), 
        - expo
TOL : 10      , for i while (i <= N) and (bool = true) 
                    a + b
do (indice : i, p : -----, p : redondeo(p, expo + 2), fp : f(p), 
                      2
fp : redondeo(fp, expo + 2), fb : f(b), fb : redondeo(fb, expo + 2), 
     b - a
er : -----, er : redondeo(er, expo + 2), fafp : redondeo(fa fp, expo + 2), 
       2
if ((fa < 0) and (fb < 0)) or ((fa > 0) and (fb > 0))
 then (print("No hay cambio de signo"), bool : false), 
tabla : addrow(tabla, [i, a, b, p, fa, fb, fp, fafp, er]), 
if (fp = 0) or (er < TOL) then (print("tolerancia cumplida"), bool : false)
 elseif fafp > 0 then (a : p, fa : fp) else b : p), 
if indice = N then (print(concat("Parametro N=", N, 
" se cumplio. Hay cambios de signo f(a) f(b)")), 
print("en las iteraciones hechas.")), display(indice, N), return(tabla))
(%i5) f(x):=x-2^-x;
                                            - x
(%o5)                          f(x) := x - 2
(%i6) biseccion(0,1,3,3);
Parametro N=3 se cumplio. Hay cambios de signo f(a) f(b) 
en las iteraciones hechas. 
                                  indice = 3

                                     N = 3

      [ N   a    b      p      f(a)      f(b)     f(p)     f(a) f(p)  error ]
      [                                                                     ]
      [ 1   0    1     0.5     - 1.0     0.5    - 0.20711   0.20711    0.5  ]
(%o6) [                                                                     ]
      [ 2  0.5   1    0.75   - 0.20711   0.5     0.1554    - 0.03218  0.25  ]
      [                                                                     ]
      [ 3  0.5  0.75  0.625  - 0.20711  0.1554  - 0.02342   0.00485   0.125 ]
(%i7) 
Run Example
base(n,d):=block([q:0, r:n, obase:d], while((n>
=d)) do (q:q+1, r:r-d, concat(q,r)));
(%o1) base(n, d) := block([q : 0, r : n, obase : d], 
                         while n >= d do (q : q + 1, r : r - d, concat(q, r)))
(%i2) 
Run Example
numer : true;
(%o1)                                true
(%i2) f(x):= cos(x) + %e^(-x);
                                               - x
(%o2)                       f(x) := cos(x) + %e
(%i3) a:1.5;
(%o3)                                 1.5
(%i4) b:2;
(%o4)                                  2
(%i5) tol: 10^(-1);
(%o5)                                 0.1
(%i6) M:matrix(["pm", "f(pm)", "err rel"]);
(%o6)                       [ pm  f(pm)  err rel ]
(%i7) if f(a) * f(b) <
 0 then    err: abs(b-a)/(b);
(%o7)                                0.25
(%i8) pm : (a+b)/2;
(%o8)                                1.75
(%i9) while(err>
tol) do(pm : (a+b)/2,M:addrow(M, [pm,f(pm),err]),if f(a) * f(pm)  <
 0  then b: pm  else a: pm, err: abs(b-a)/(b));
(%o9)                                done
(%i10) M;
               [  pm           f(pm)              err rel      ]
               [                                               ]
(%o10)         [ 1.75   - 0.0044721121990469        0.25       ]
               [                                               ]
               [ 1.625    0.14273454017726    0.14285714285714 ]
(%i11) 
[abs,addrow,args,block,copymatrix,disp,do,lambda,length,map,matrix,or,rowswap,while] [abs,addrow,cos,do,matrix,numer,true,while] [abs,and,block,col,copy,create_list,fpprintprec,genmatrix,ident,invert,kill,length,lmax,makelist,matrix_size,random,submatrix,sum,while] [abs,and,block,col,copy,fpprintprec,genmatrix,ident,invert,length,lmax,makelist,matrix_size,random,submatrix,sum,while] [abs,asin,display,do,float,numer,while] [abs,asin,display,do,numer,while] [abs,asin,do,numer,print,while] [abs,block,diff,do,ev,print,while] [abs,cos,diff,do,ev,numer,print,true,while] [abs,cos,do,numer,print,true,while] [abs,do,float,if,while] [abs,do,print,while] [addrow,block,concat,display,false,if,log,matrix,numer,print,return,round,true,while] [addrow,block,concat,display,if,log,matrix,numer,print,return,round,true,while] [addrow,block,concat,false,if,log,matrix,numer,print,return,round,true,while] [addrow,block,display,if,log,matrix,numer,print,return,round,true,while] [addrow,block,if,log,matrix,numer,print,return,round,true,while] [append,block,buildq,declare,delete,do,false,first,floor,if,last,length,map,not,return,show,simp,true,while] [append,block,draw2d,fpprec,fpprintprec,sqrt,while] [append,block,fpprec,fpprintprec,plot2d,sqrt,while] [asin,display,do,while] [bfloat,block,floor,fpprec,print,sign,sum,while] [bfloat,block,floor,fpprec,sign,sum,while] [block,concat,do,kill,makelist,obase,return,stringdisp,true,while] [block,concat,do,kill,makelist,obase,return,while] [block,concat,do,makelist,obase,return,while] [block,do,fix,if,mod,while] [block,do,if,length,makelist,random,while] [block,do,if,length,makelist,while] [block,do,if,length,while] [block,do,ifactors,length,num,return,while] [block,do,length,while] [block,do,makelist,plot2d,while] [block,do,mod,return,while] [block,do,plot2d,while] [block,do,while] [block,inv_mod,print,while] [coeff,denom,ev,expand,linsolve,nterms,part,while] [coeff,do,ev,expand,hipow,linsolve,nterms,num,part,print,while] [coeff,do,ev,expand,hipow,linsolve,nterms,num,part,while] [coeff,do,ev,expand,hipow,linsolve,nterms,part,print,while] [coeff,do,ev,expand,hipow,linsolve,print,while] [coeff,ev,expand,linsolve,nterms,part,while] [display,do,while] [do,exp,false,if,max,print,random,solve,while] [do,mod,print,while] [do,mod,while] [do,primep,while] [do,print,while] [while]

Related Help

Help for While