Sponsored links: Algebra eBooks
 

Help Index

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

The Maxima on-line user's manual

Algebra Calculator

Search:

Printf Calculator

Printf

Function: printf (<dest>, <string>)

kill(all);
bertrandparadox(n):=block(cont:0,for i:1 thru n do(    x1:-1.0 + random(2.0),    signo:random(2),    if signo=0 then y1:sqrt(1-x1^2) else y1:-sqrt(1-x1^2),    /*printf(true,"~f ~f~%",x1,y1),*/    x2:-1.0 + random(2.0),    signo:random(2),    if signo=0 then y2:sqrt(1-x2^2) else y2:-sqrt(1-x2^2),    /*printf(true,"~f ~f~%",x2,y2),*/    longcuerda:sqrt((x2-x1)^2+(y2-y1)^2),    /*print(longcuerda),*/    if longcuerda>=sqrt(3) then cont:cont+1    ),/*print(cont),*/return(float(cont/n)));
bertrandparadox(1000);

Function: printf (<dest>, <string>, <expr_1>, ..., <expr_n>) Makes the Common Lisp function FORMAT available in Maxima. (From gcl.info: "format produces formatted output by outputting the characters of control-string string and observing that a tilde introduces a directive. The character after the tilde, possibly preceded by prefix parameters and modifiers, specifies what kind of formatting is desired. Most directives use one or more elements of args to create their output.")

The following description and the examples may give an idea of using printf. See a Lisp reference for more information.

~% new line ~& fresh line ~t tab ~$ monetary ~d decimal integer ~b binary integer ~o octal integer ~x hexadecimal integer ~br base-b integer ~r spell an integer ~p plural ~f floating point ~e scientific notation ~g ~f or ~e, depending upon magnitude ~h bigfloat ~a uses Maxima function string ~s like ~a, but output enclosed in "double quotes" ~~ ~ ~< justification, ~> terminates ~( case conversion, ~) terminates ~[ selection, ~] terminates ~{ iteration, ~} terminates

Note that the selection directive ~[ is zero-indexed. Also note that the directive ~* is not supported.

          (%i1) printf( false, "~a ~a ~4f ~a ~@r",
                        "String",sym,bound,sqrt(12),144), bound = 1.234;
          (%o1)                 String sym 1.23 2*sqrt(3) CXLIV
          (%i2) printf( false,"~{~a ~}",["one",2,"THREE"] );
          (%o2)                          one 2 THREE
          (%i3) printf(true,"~{~{~9,1f ~}~%~}",mat ),
                    mat = args(matrix([1.1,2,3.33],[4,5,6],[7,8.88,9]))$
                1.1       2.0       3.3
                4.0       5.0       6.0
                7.0       8.9       9.0
          (%i4) control: "~:(~r~) bird~p ~[is~;are~] singing."$
          (%i5) printf( false,control, n,n,if n=1 then 0 else 1 ), n=2;
          (%o5)                    Two birds are singing.

If <dest> is a stream or true, then printf returns false. Otherwise, printf returns a string containing the output.

There are also some inexact matches for printf. Try ?? printf to see them.

(%o1)                                true
(%i2) 

Printf Example

Related Examples

printf

f(a):= a[1] + a[2]*(2...

f2(a):= f(a[1]) + f(a...

b:[[1,3408,1,1507328,...

Calculate

printf

f(a):= a[1] + a[2]*(2...

f2(a):= f(a[1]) + f(a...

b:[[1,3408,1,1507328,...

Calculate

printf

/* Definintion von zw...

b:[false,false,true,t...

/* Definition einer V...

Calculate

printf

f(a):= a[1] + a[2]*(2...

f2(a):= f(a[1]) + f(a...

b:[[1,3408,1,1507328,...

Calculate

printf

f(a):= a[6] + a[5]*(2...

f2(a):= f(a[1]) + f(a...

b:[[1,3408,1,1507328,...

Calculate

printf

/* Definintion von zw...

a:[false,true,false,t...

b:[false,false,true,t...

Calculate

printf

f(x) := 1/(1-x*p);

printf (false, "~% ~a...

Calculate