Examples

This is a small tour of the capabilities Yacas currently offers. Note that this list of examples is far from complete. Yacas contains a few hundred commands, of which only a few are shown here.

Additional example calculations including the results can be found here:


Miscellaneous capabilities

100!;
Compute a large factorial using arbitrary precision integers.

ToBase(16,255);
FromBase(16,"2FF");
Convert between the decimal notation and another number base. (In Yacas, all numbers are written in decimal notation.)

Expand((1+x)^5);
Expand the expression into a polynomial.

Apply("+",{2,3});
Apply an operator to a list of arguments. This example would evaluate to 5.

Apply({{x,y},x+y},{2,3});
Apply a pure function to a list of arguments. This example would also evaluate to 5.

D(x)D(x) Sin(x);
Take derivatives of a function.

Solve(a+x*y==z,x);
Solve an equation for a variable.

Taylor(x,0,5) Sin(x);
Calculate the Taylor series expansion of a function.

Limit(x,0) Sin(x)/x;
Calculate the limit of a function as a variable approaches a value.

Newton(Sin(x),x,3,0.0001);
Use Newton's method for numerically finding a zero of a function.

DiagonalMatrix({a,b,c});
Create a matrix with the elements specified in the vector on the diagonal.

Integrate(x,a,b) x*Sin(x);
Integrate a function over variable x, from a to b.

Factors(x^2-1);
Factorize a polynomial.

Apart(1/(x^2-1),x);
Create a partial fraction expansion of a polynomial.


A longer calculation with plotting

Here is an example of a semi-realistic numerical calculation using Yacas. The task was to visualize a particular exact solution of an elliptical differential equation. The solution was found as an infinite series. We need to evaluate this infinite series numerically and plot it for particular values of the parameters.

The function g(q,phi,chi) is defined by

g(q,phi,chi)=1/(2*Pi)*Sin(q*phi)/Sin(2*q*phi)+1/Pi*Sum(n,0,Infinity,Cos(n*chi)*Sin(Sqrt(q^2-n^2)*phi)/Sin(2*Sqrt(q^2-n^2)*phi)).

Here q, phi and chi are numerical parameters of the problem. We would like to plot this series evaluated at fixed q and phi as function of chi between 0 and 2*Pi.

To solve this problem, we prepare a separate file with the following Yacas code:

    /* Auxiliary function */
g1(n, q, phi, chi) := [
    Local(s);
    s := q^2-n^2;
    N(Cos(n*chi) * If(s=0,
        1/2,    /* Special case of s=0:
		avoid division by 0 */
        Sin(Sqrt(s)*phi)/Sin(2*Sqrt(s)*phi)
		  /* now s != 0 */
            /* note that Sqrt(s) may
			  be imaginary here */
        )
    );
];
    /* Main function */
g(q, phi, chi) := [
    Local(M, n);
    M := 16;
	  /* Exp(-M) will be the precision */
      /* Use N() to force numerical
	    evaluation */
    N(1/2*Sin(q*phi)/Sin(2*q*phi)) +
        /* Estimate the necessary number
		  of terms in the series */
    Sum(n, 1, N(1+Sqrt(q^2+M^2/phi^2)),
	  g1(n, q, phi, chi)) ;
];
    /* Parameters */
q:=3.5;
phi:=2;
    /* Make a function for plotting:
	  it must have only one argument */
f(x) := g(q, phi, x);
   /* Plot from 0 to 2*Pi with 80 points */
Plot2D(f(x), 0: 2*Pi);

Name this file "fun1" and execute this script by typing

Load("fun1");
After this you should see a window with a plot.