printf

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 603
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

printf

Message par compsystems » lun. mars 19, 2018 2:15 pm

Hello BP

Please inform me where I can find more documentation about printf, printf allows some features of printf of c as %d, %x, ...?

I think the print string in the following example should also be printed in 2D

Code : Tout sélectionner

DispG; ClrIO; a:=4; b:=2.5; printf("sqrt(%gen)+(%gen)^2=%gen",a,b,sqrt(a)+b^2 ); Pause; DispHome;
Console =>
sqrt(4)+(2.5)^2=8.25

Console (2D) =>
√4+2.5²=8.25

Idea
with simple quotes prints the string exactly as it was written

Code : Tout sélectionner

DispG; ClrIO; a:=4; b:=2.5; printf('sqrt(%gen)+(%gen)^2=%gen',a,b,sqrt(a)+b^2 ); Pause; DispHome;
Console =>
sqrt(4)+(2.5)^2=8.25

Another Idea, that the expression function can convert to 2D expression

Code : Tout sélectionner

DispG; ClrIO; a:=4; b:=2.5; printf(expr("sqrt(%gen)+(%gen)^2=%gen"),a,b,sqrt(a)+b^2 ); Pause; DispHome;

parisse
Messages : 5882
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: printf

Message par parisse » lun. mars 19, 2018 5:08 pm

You can do something like

Code : Tout sélectionner

b:=4;printf("sqrt(%gen)+(%gen)=%gen",a,'b^2',sqrt(a)+b^2 );
but if you quote b^2 then b is not replaced by 4.

compsystems
Messages : 603
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: printf

Message par compsystems » mar. mars 20, 2018 8:08 pm

a simple mistake, when printed for the first time, the line is overwritten

Code : Tout sélectionner

DispG;printf("x^2\nx^3");

parisse
Messages : 5882
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: printf

Message par parisse » mer. mars 21, 2018 7:30 am

Ok, I will remove "Step by step console".

compsystems
Messages : 603
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: printf

Message par compsystems » mer. mars 21, 2018 1:21 pm

parisse a écrit :Ok, I will remove "Step by step console".
when starting DipsG display the message, then on the first impression delete the message =)

The following code is paused after each print, please attach a [esc] button to abort execution, otherwise if there are many Pauses, you would have to execute them all

Code : Tout sélectionner

testPause():={
        local x,y;
        assume(x,symbol);assume(y,symbol);
        autosimplify(nop);
        DispG; 
        printf; 
        printf( "Console, 2D printing" ); Pause;
        printf( "" );
        printf( "Expr1:" ); 
        printf( 'f(x):=x^3-2*x^2+1*x-1' ); Pause;
        printf( f(x):=x^3-2*x^2+1*x-1 ); Pause;
        printf( f(x) ); Pause;;
        
        printf( "" );
        printf( "Expr2:" ); 
        printf( 'x^3-2*x^2+1*x-1 | x=y' ) Pause;
        printf( x^3-2*x^2+1*x-1 | x=y ); Pause;
        printf( f(y) ); Pause;;
        
        printf( "" );
        printf( "Expr3:" );
        printf( 'g(x):=1/(x+3)' ); Pause;
        printf( g(x):=1/(x+3) ); Pause;
        printf( g(x) ); Pause;
   
        printf( "" );     
        printf( "Expr4:" );
        printf( 'f(g(x))' ); Pause;
        printf( f(g(x)) ); Pause;

        printf( "" );     
        printf( "Expr5:" );        
        printf( 'g(f(x))' ); Pause;
        printf( g(f(x)) ); Pause;
         
        return "Done"

}:;
The following code, shows an exercise of the solution of a system, as you can see at the end it performs the verification by means of graphing.

could you please think about incorporating an argument to DispG

DispG(1) starts the view, equal to DispG cmd
DispG(0) closes the view, equal to DispHome cmd
DispG(-1) hides the graphing plane, new functionality

Code : Tout sélectionner

testPrintf():={
	local y,x,list0,expr0,lsolx,y1,y2,sols,test1;
	purge(x,y);
	autosimplify(nop); autosimplify();
	approx_mode(0); approx_mode();
	DispG; ClrIO; printf("Solving a system of two equations"); printf("Solve the following system:");
	list0 := [ y = x^2, y = 2*x + 3 ]; printf(list0);
	printf("substitute y = x² in y = 2x + 3:");
	expr0 := subst(list0(2),list0(1)); printf(expr0);
	printf("substract 2x + 3:");
	expr0 := expr0-(2*x + 3); printf(expr0);
	printf("simplify:");
	expr0 := simplify(expr0); printf(expr0);
	printf("factor:"); 
	expr0 := factor(expr0); printf(expr0);
	printf("zero factor theorem:"); 
	lsolx := [ part(left(expr0),1)=0, part(left(expr0),2)=0 ]; printf(lsolx);
	printf("First factor plus 3, second minus 1:");
	lsolx := [lsolx(1)+3, lsolx(2)-1 ]; printf(eval(lsolx,1));
	printf("simplify"); printf("x values:");
	lsolx := simplify(lsolx); printf(lsolx);
	printf("y values:"); printf("Replace x values in the system, firts equation"); 
	y1 := subst(list0(1),lsolx(1)); printf(y1);
	printf("Replace x values in the system, second equation");
	y2 := subst(list0(1),lsolx(2)); printf(y2);
	printf("Solutions shaped as a array");
	sols:=[[lsolx(1),y1],[lsolx(2),y2]]; printf(sols); 
	printf("Checking results:"); printf("Replace x and y values in the system, firts equation"); 
	test1 := subst(list0(1),[sols(1,1),sols(1,2)]); printf(test1);
	printf("Evaluate:");
	test1 := evalb(test1); printf(test1);
	printf("Replace x and y values in the system, second equation"); 
	test1 := subst(list0(1),[sols(2,1),sols(2,2)]); printf(test1); 
	printf("Evaluate:");
	test1 := evalb(test1); printf(test1);
	sols := solve([ y = x^2, y = 2*x + 3 ],[x,y]); printf("Solutions:"); printf(sols);
	printf("Solutions shaped as a boolean expression:");
	sols := list2exp(sols,[x,y]); printf(eval(sols,1));
	printf("Graphing"); 
	plot([x^2,2*x+3],x); 
	return("Done"); 
}:;

parisse
Messages : 5882
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: printf

Message par parisse » mer. mars 21, 2018 4:04 pm

Sorry, modifying DispG would be too complicated, just call Pause() less often.

Répondre