Sei sulla pagina 1di 4

Programacion con MATHEMATICA

CICLOS DO
Se usan para repetir una expresion o
evaluacion un numero FIJO HpredeterminadoL de
veces. Aunque existen comandos de MATHEMATICA para detener
un ciclo en ejecucion, antes de este numero predeterminado.
Do@expr, 8imax <D evaluatesexpr imax times.
Do@expr, 8i, imax <D
evaluatesexprwith the variablei
successively taking on the values1through imax Hin steps of1L
Do@expr, 8i, imin, imax <D
starts with i = imin
Do@expr, 8i, imin , imax , di<D
uses stepsdi.

In[1]:=

Do@Print@nD, 8n, 1, 5<D

AyudaEnProgramacion.nb

1
2
3
4
5

CICLOS FOR
Se usan para repetir una expresion o
evaluacion MIENTRAS la prueba HtestL sea VERDADERA.
Este ciclo es conveniente para mtodos de
Newton o cualquier metodo que requiera que
se hagan los calculos hasta que el error sea
menor a una tolerencia predeterminada.
For@start, test, incr, bodyD
executes start, then repeatedly evaluates body and incr until test
fails to give True.

In[2]:=

For@i = 0, i < 4, i ++, 8Print@iD, Print@" still working "D<D

AyudaEnProgramacion.nb

0
still working
1
still working
2
still working
3
still working

INSTRUCCION

IF

Es el comando Condicional. Si la
prueba es ciera se ejecuta una accion,
y si es falsa puede o no ejecutarse una segunda accion,
dependiendo de la instruccion.
If@condition, t, f D
gives t if condition evaluates to True, and f if it evalu
ates to False.

In[3]:=

Out[3]=

x=5
If@x > 7, Print@"x es mayor a 7 "D, Print@"La prueba es falsa "DD
5

La prueba es falsa
In[5]:=

If@x > 7, Print@"x > 7 "DD


H Fijarse que como no se indico accion en caso de False, no se hace nada L

"If" tambien es usado para definir funciones


entre llaves usadas en los curso de calculo

AyudaEnProgramacion.nb

In[6]:=

F@x_D := If@x 0, x, xD
Plot@F@zD, 8z, 2, 2<D

H Definicion de la funcion valor absoluto L

2.0

1.5

1.0

Out[7]=

0.5

-2

-1

Operadores LOGICOS
Se usan para definir pruebas o condiciones mas complejas.

And I&&, flM Or I, fiM Not I! , M Nand I M Nor I M


Xor I M Xnor I M Implies I M Equivalent I M Majority
True , False symbolic truth values
Boole convert symbolic truth values to 0 and 1

Potrebbero piacerti anche