Está en la página 1de 22

Prctica N6

6.1. Estructura repetitiva desde (for)


Inicio
6.1.1Hacer un programa para calcular el factorial de un nmero n.

Leer: n

f=1

for i=1:n

f=f*i Escribir:; factorial

Fin
%Este programa calcula el factorial de un nmero n=input('ingrese un nmero:'); f=1; for i=1:n f=f*i; end

fprintf('el factorial es:%8.2f\n',f)

>> factorial ingrese un nmero:3 el factorial es: 6.00 >> factorial ingrese un nmero:5 el factorial es: 120.00

6.1.2. disee un programa con la estructura desde que calcule el total apagar polr la compra de polos. Si se compran 5 o mas polos sele aplicaran un descuento de 15% sobre el total de la compra y si es menor de 5 polos se le aplica un descuento de 12% sobre el total de la compra.

Inicio

Leer: n

sum=0

for i=1:n

Leer: cam

f=f*i

If n>=5

tp=0.88*sum

tp=0.85*sum

Escribir: total pagar

Fin

%Este programa calcula el total a pagar por la compra de polos n=input('ingrese la cantidad de polos:');

sum=0; for i=1:n pcam=input('ingrese precio de polo:'); sum=sum+pcam; end if n>=5 tp=0.85*sum; else tp=0.88*sum; end fprintf('el total a pagar es:%8.2f\n',tp)

>> polos ingrese la cantidad de polos:4 ingrese precio de polo:5 ingrese precio de polo:5 ingrese precio de polo:6 ingrese precio de polo:1 el total a pagar es: 14.96 >> polos ingrese la cantidad de polos:5 ingrese precio de polo:5 ingrese precio de polo:5 ingrese precio de polo:6 ingrese precio de polo:1 ingrese precio de polo:4.25 el total a pagar es: 18.06

6.1.3 disee un programa que muestre la tabla de multiplicar del 1 al 30 para cualquier nmero.

Inicio

Leer: n

for i=1:30

multi=n*i fin

multiplicaci n

%Este programa muestra la tabla de multiplicar del 1 al 30 para cualquier %nmero n=input('ingrese un nmero:'); for i=1:30 multi=n*i; fprintf('la multiplicacion es :%8.2f\n',multi) end

>> tabla ingrese un nmero:4 la multiplicacion es : 4.00 la multiplicacion es : 8.00 la multiplicacion es : 12.00 la multiplicacion es : 16.00 la multiplicacion es : 20.00 la multiplicacion es : 24.00 la multiplicacion es : 28.00 la multiplicacion es : 32.00

la multiplicacion es : 36.00 la multiplicacion es : 40.00 la multiplicacion es : 44.00 la multiplicacion es : 48.00 la multiplicacion es : 52.00 la multiplicacion es : 56.00 la multiplicacion es : 60.00 la multiplicacion es : 64.00 la multiplicacion es : 68.00 la multiplicacion es : 72.00 la multiplicacion es : 76.00 la multiplicacion es : 80.00 la multiplicacion es : 84.00 la multiplicacion es : 88.00 la multiplicacion es : 92.00 la multiplicacion es : 96.00 la multiplicacion es : 100.00 la multiplicacion es : 104.00 la multiplicacion es : 108.00 la multiplicacion es : 112.00 la multiplicacion es : 116.00 la multiplicacion es : 120.00

6.1.4 una tienda ofrece un descuento del 12% del total de la compra y un cliente desea saber cuanto deber pagar finalmente por una compra realizada hacer un programa con la estructura desde.

Inicio

Leer: n

sum=0

for i=1:n

leer:

d=0.12*sum sum=sum+comp

tcomp=sum-d

Escribir: total de compra

Fin

%Este programa determina el pago final de una compra realizada n=input('ingrese la cantidad de artculos:'); sum=0; for i=1:n comp=input('ingese el precio del artculo:'); sum=sum+comp; end d=0.12*sum; tcomp=sum-d; fprintf('el total de la compra es:%8.2f\n',tcomp)

>> compra ingrese la cantidad de artculos:7 ingese el precio del artculo:5 ingese el precio del artculo:5 ingese el precio del artculo:5 ingese el precio del artculo:5 ingese el precio del artculo:5 ingese el precio del artculo:5 ingese el precio del artculo:5 el total de la compra es : 30.80

1.1 comandos de ayuda ejercicio 1


>> help sin SIN Sine of argument in radians. SIN(X) is the sine of the elements of X.

See also asin, sind.

Overloaded methods: codistributed/sin sym/sin

Reference page in Help browser doc sin >> help cos COS Cosine of argument in radians. COS(X) is the cosine of the elements of X.

See also acos, cosd.

Overloaded methods: codistributed/cos sym/cos

Reference page in Help browser doc cos

>> help tan TAN Tangent of argument in radians. TAN(X) is the tangent of the elements of X.

See also atan, tand, atan2.

Overloaded methods: codistributed/tan sym/tan

Reference page in Help browser

doc tan

>> help atan ATAN Inverse tangent, result in radians. ATAN(X) is the arctangent of the elements of X.

See also atan2, tan, atand.

Overloaded methods: codistributed/atan sym/atan

Reference page in Help browser doc atan

>> help acos ACOS Inverse cosine, result in radians. ACOS(X) is the arccosine of the elements of X. Complex results are obtained if ABS(x) > 1.0 for some element.

See also cos, acosd.

Overloaded methods: codistributed/acos sym/acos

Reference page in Help browser doc acos

>> help sec SEC Secant of argument in radians. SEC(X) is the secant of the elements of X.

Class support for input X: float: double, single

See also asec, secd.

Overloaded methods: codistributed/sec sym/sec

Reference page in Help browser doc sec

>> help csc CSC Cosecant of argument in radians. CSC(X) is the cosecant of the elements of X.

Class support for input X: float: double, single

See also acsc, cscd.

Overloaded methods: codistributed/csc sym/csc

Reference page in Help browser doc csc

>> help cot COT Cotangent of argument in radians. COT(X) is the cotangent of the elements of X.

Class support for input X: float: double, single

See also acot, cotd.

Overloaded methods: codistributed/cot sym/cot

Reference page in Help browser doc cot

>> help asec

ASEC Inverse secant, result in radians. ASEC(X) is the inverse secant of the elements of X.

Class support for input X: float: double, single

See also sec, asecd.

Overloaded methods: codistributed/asec sym/asec

Reference page in Help browser doc asec

>> help acot ACOT Inverse cotangent, result in radian. ACOT(X) is the inverse cotangent of the elements of X.

Class support for input X: float: double, single

See also cot, acotd.

Overloaded methods: codistributed/acot

sym/acot

Reference page in Help browser doc acot

>> help sinh SINH Hyperbolic sine. SINH(X) is the hyperbolic sine of the elements of X.

See also asinh.

Overloaded methods: codistributed/sinh sym/sinh

Reference page in Help browser doc sinh

>> help cosh COSH Hyperbolic cosine. COSH(X) is the hyperbolic cosine of the elements of X.

See also acosh.

Overloaded methods: codistributed/cosh

sym/cosh

Reference page in Help browser doc cosh

>> help acosh ACOSH Inverse hyperbolic cosine. ACOSH(X) is the inverse hyperbolic cosine of the elements of X.

See also cosh.

Overloaded methods: codistributed/acosh sym/acosh

Reference page in Help browser doc acosh

>> help atanh ATANH Inverse hyperbolic tangent. ATANH(X) is the inverse hyperbolic tangent of the elements of X.

See also tanh.

Overloaded methods: codistributed/atanh

sym/atanh

Reference page in Help browser doc atanh

>> help exp EXP Exponential. EXP(X) is the exponential of the elements of X, e to the X. For complex Z=X+i*Y, EXP(Z) = EXP(X)*(COS(Y)+i*SIN(Y)).

See also expm1, log, log10, expm, expint.

Overloaded methods: lti/exp codistributed/exp fints/exp xregcovariance/exp sym/exp

Reference page in Help browser doc exp

>> help log LOG Natural logarithm. LOG(X) is the natural logarithm of the elements of X. Complex results are produced if X is not positive.

See also log1p, log2, log10, exp, logm, reallog.

Overloaded methods: gf/log codistributed/log fints/log designdev/log sym/log

Reference page in Help browser doc log

>> help log10 LOG10 Common (base 10) logarithm. LOG10(X) is the base 10 logarithm of the elements of X. Complex results are produced if X is not positive.

Class support for input X: float: double, single

See also log, log2, exp, logm.

Overloaded methods: codistributed/log10 fints/log10

sym/log10

Reference page in Help browser doc log10

>> help log2 LOG2 Base 2 logarithm and dissect floating point number. Y = LOG2(X) is the base 2 logarithm of the elements of X.

[F,E] = LOG2(X) for each element of the real array X, returns an array F of real numbers, usually in the range 0.5 <= abs(F) < 1, and an array E of integers, so that X = F .* 2.^E. Any zeros in X produce F = 0 and E = 0. This corresponds to the ANSI C function frexp() and the IEEE floating point standard function logb().

See also log, log10, pow2, nextpow2, realmax, realmin.

Overloaded methods: codistributed/log2 fints/log2 sym/log2

Reference page in Help browser doc log2

>> help sign

SIGN Signum function. For each element of X, SIGN(X) returns 1 if the element is greater than zero, 0 if it equals zero and -1 if it is less than zero. For the nonzero elements of complex X, SIGN(X) = X ./ ABS(X).

See also abs.

Overloaded methods: codistributed/sign

Reference page in Help browser doc sign

ejercicio 2
>> sind(37)

ans =

0.6018

>> tand(53)

ans =

1.3270

>> secd(60)

ans =

2.0000

>> cotd(30)

ans =

1.7321

>> asecd(2)

ans =

60.0000

>> asind(sqrt(2)/2)

ans =

45.0000

>> acscd(2*sqrt(3)/3)

ans =

60.0000

>> acosd(4/5)

ans =

36.8699

>> log(exp(2))

ans =

>> log10(1000)

ans =

>> log10(log10(exp(4)))

ans =

0.2398

>> log(log10(exp(3)))*asin(sqrt(3)/2)

ans =

0.2771

>> log(log10(log(log10(exp(exp(3))))))

ans =

-1.0917

También podría gustarte