Atin Maple

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

EXPERIMENT NUMBER: 1

Objective: Working of Computation software.


Description: Maple provides an interactive problem-solving environment,
complete with procedures for performing symbolic, numeric, and graphical
computations. At the core of the Maple computer algebra system is a powerful
programming language, on which the Maple libraries of mathematical
commands are built.
The Maple software consists of two distinct parts.
• The user interface
• The computation engine
The User Interface
You can use the Maple user interface to enter, manipulate, and analyze
mathematical expressions and commands. The user interface communicates with
the Maple computation engine to solve mathematical problems and display their
solutions.
The Computation Engine
The Maple computation engine is the command processor, which consists of two
parts: the kernel and math library.
The kernel is the core of the Maple computation engine. It contains the essential
facilities required to run and interpret Maple programs, and manage data
structures.

The math library contains most of the Maple commands. It includes functionality
for numerous mathematical domains, including calculus, linear algebra, number
theory, and combinatorics.

Maple Statements:
A statement is a single complete piece of code that Maple can execute. There are
many types of statements in Maple, including expression statements, assignment
statements, selection statements (if ... then)
Statements in Maple must be terminated with a semicolon (;) or a colon (:).
Statements can be run in Maple one at a time, or multiple statements can be run on
one line. If multiple statements are run on one line, the statements must be
separated by a statement separator, either a semicolon (;) or a colon (:).
At the top level, the output of a statement that ends with a colon is hidden.
> a:=2: a^2;
4
Expression Statements:
The simplest kind of statement in Maple is the expression statement. It consists of
an arbitrary expression, whose evaluation constitutes the effect of the statement.
> Pi;
Π
Assignments:
Assignment statements allow you to associate a value or expression with a name.
Here, the name a has no assigned value, so it evaluates to itself.
> a;
A
The following assignment statement associates the value 2 / 3 with the name a.
> a := 2 / 3;
a≔23

Flow Control:
A number of Maple statements are used to direct the flow of control in a program; that
is, the sequence in which the various statements of the program are run.

Sequencing:
The simplest form of a Maple program is a sequence of zero or more statements,
separated either by semicolons or colons. A sequence of statements is run in the order
in which they are entered.
For example, running these three statements
> a := 2;
a≔2
> b := 3;
b≔3
> sin( a + b );
sin(5)
executes the assignment to the name a, then the assignment to the name b is executed
and, finally, the value of the expression sin( a + b ) is computed.
Branching
The most general form of an if statement can have several conditions, corresponding
consequents, and an optional alternative branch. This general form has the syntax:
if condition1 then
consequent1
elif condition2 then
consequent2
....
Else
Alternative
end if

in which there can be any number of branches preceded by elif. The effect of this
general form of the if statement is to divert the flow of control into the first branch
whose conditional expression evaluates to true. This means that the order of
the elif branches can affect the behavior of the if statement.
The branch introduced by else is optional. If it is present, and none of the earlier
condition expressions evaluates to true, then control flows into the else branch. If it is
not present, and none of the earlier condition expressions evaluates to true, then the
flow of execution continues with the first statement following the entire if statement.

OUTPUT:

1. Write a maple script to generate the following Sequence:


2,6,10,14,18.
2. Write a maple script to find the given number is odd or even.

3. Write a maple script for solving the following quadratic equation.


EXPERIMENT NUMBER: 2

Objective: Practice of various set operations in maple.


Description:

SETS:
A set is an unordered collection of objects that we usually denote by capital letters.
The objects in a set are called its elements, or members, which are contained by the
set. The notation {a, b, c, d, e} represents the set of the five elements a, b, c, d and
e. We use the symbols and to indicate membership of an element in a set. In maple
we can do the following:

SET OPERATIONS:
Subset
The set A is said to be a subset of B, denoted A ⊆ B, if and only if every element of
A is also an element of B. In Maple:

Union: The union of sets A and B, denoted by A B , is the set defined as

A B={x|x A x B}

Example 1: If A = {1, 2, 3} and B = {4, 5} , then A B = {1, 2, 3, 4, 5} .


Example 2: If A = {1, 2, 3} and B = {1, 2, 4, 5} , then A B = {1, 2, 3, 4, 5} .
In maple:

Intersection: The intersection of sets A and B, denoted by A B , is the set


defined as..

A B={x|x A x B}

Example 3: If A = {1, 2, 3} and B = {1, 2, 4, 5} , then A B = {1, 2} .


Example 4: If A = {1, 2, 3} and B = {4, 5} , then A B= .
Difference: The difference of sets A from B , denoted by A - B , is the set defined
as A - B = { x | x A x B }

Example 5: If A = {1, 2, 3} and B = {1, 2, 4, 5} , then A - B = {3} .


Example 6: If A = {1, 2, 3} and B = {4, 5} , then A - B = {1, 2, 3} .
Note that in general A - B B–A
In maple:

POWER SET:
Given a set A, the power set of S is the set of all subsets of the set S. The power set
of S is denoted by P(S). The set theory notation for power set is P S( ) = { A | A S }
or X P(S) def X S. In order to find the power set in maple it will be necessary to
import the library that has that command. To import a library we use the with
command as follows:
]>with(combinat,powersets): ]>powerset({1,2});
{{},{1},{1,2},{2}}

In Maple:

EXPERIMENT NUMBER: 3

Objective: To understand Calling sequence: Procedures in maple.


Description: A Maple procedure (a type of program) is a group of statements that
are processed together. The easiest way to create a Maple procedure is to enclose a
sequence of commands, which can be used to perform a computation interactively,
between the proc(...) and end proc statements.

Entering a Procedure Definition


The following procedure generates the string "Hello World". Enter this procedure
in a Maple session by entering its definition on one line.
> hello := proc() return "Hello World"; end proc;
hello≔proc()return"Hello World"end proc

To run this procedure, enter its name followed by a set of parentheses and a
semicolon:
> hello();
"Hello World"
OUTPUT:
OUTPUT:
EXPERIMENT NUMBER: 4

Objective: Recursion in maple.


Description: A recursive function is a function that calls itself, meaning it uses
its own previous terms in calculating subsequent terms.
Following are two examples of recursion:

Fibonacci series:
The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …….
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the
recurrence relation
Fn = Fn-1 + Fn-2
with seed values
F0 = 0 and F1 = 1.

Snapshot of Fibonacci series:


Factorial of a given number:
The factorial of a positive number n is given by:
factorial of n (n!) = 1*2*3*4....n

The factorial of a negative number doesn't exist. And the factorial of 0 is 1.

Snapshot of Factorial series:


EXPERIMENT NUMBER: 5
Objective: Counting.
Description: Given a positive integer N, count all possible distinct binary strings
of length N such that there are no consecutive 1’s.
Examples:
Input: N = 2
Output: 3
The 3 strings are 00, 01, 10

Input: N = 3
Output: 5
The 5 strings are 000, 001, 010, 100, 101
OUTPUT:

EXPERIMENT NUMBER: 6
Objective: Permutations and combinations.
Description:
Calling Sequence
permute(n)
permute(n, r)
Parameters
N - list/set of objects or an integer
R - (optional) integer

Description

If n is a list or set, then permute returns a list of all the permutations of the
elements of n, taken r at a time. If n is a non-negative integer, it is interpreted in
the same way as a list of the first n integers. If r is not specified, then it is taken to
be equal to the number of elements in n.
• The permutations are generated in order. Duplicates in n are respected.
• The function numbperm will compute the number of possible
permutations: numbperm(n, r) = nops(permute(n, r)).
• The command with(combinat,permute) allows the use of the abbreviated form of
this command.

OUTPUT:

Calling Sequence
numbcomb(n, m)
Parameters
n - list or set of expressions or a non-negative integer
m - (optional) non-negative integer
Descriptio
n
• If n is a list or set, then numbcomb counts the combinations of the
elements of n taken m at a time. If m is not given, then all
combinations are considered. If n is a non-negative integer, it is
interpreted in the same way as a set of the first n integers.
• Note that the result of numbcomb(n, m) is equivalent
to numelems(choose(n,m)). However, this number is computed either
by using binomial coefficients or by using a generating function
method.
• Additionally, note that if n is a non-negative integer, the result
of numbcomb(n, m) is identical to that of (nm).
• The count of combinations takes into account duplicates in n. In the
case where there are no duplicates, the count is given by the
formula 2n if m is not specified, or by the formula (nm) if m is
specified. If there are duplicates in the list, then the generating
function is used.
• The command with(combinat,numbcomb) allows the use of the
abbreviated form of this command.

OUTPUT:
EXPERIMENT NO.: 7

Objective: Expected Value Problems.


Description: In this problem we are given the deck of 52 cards. It includes thirteen
ranks in each of the four French suits: labeled as:
1 to 13: club
14 to 26: diamonds
27 to 39: Hearts
40 to 52: Spades
Each suit includes an ace, a king, queen and jack.

Question: Among these cards we need to select 5 cards and the no. of aces among
them. This is to be done 10 times .

SNAPSHOT:
EXPERIMENT NUMBER: 08

Objective: Binary Relations: Influence.


Description: In this problem we need to find whether a given relation is reflexive
or symmetric.

Reflexive Relation: A relation R on set A is called Reflexive if ∀a∈A is related


to a (aRa holds)
Example − The relation R={(a,a),(b,b)} on set X={a,b} is reflexive.

Symmetric Relations: A relation R on set A is called Symmetric if


xRy implies yRx, ∀x∈A and ∀y∈A.
Example − The relation R={(1,2),(2,1),(3,2),(2,3)} on set A={1,2,3} is
symmetric.

Ques1. Write a maple script to find whether the given relation is reflexive or
not.
Set A:{a,b,c}
R:{(a,b),(c,a),(a,a),(b,b),(c,c)

Ques 2. Write a maple script to find whether the given relation is symmetric
or not .Set S={a,b,c}
R={(a,b)(b,a)(a,a)(c,a)(a,c)(c,c)}
EXPERIMENT NUMBER: 09

Objective: Combinational equivalence.


Description:
1. Calling Sequence
numbperm(n)
numbperm(n, r
)
Parameters
n - a list/set of objects or an integer
R - (optional) integer
Description
• If n is a list or set, then numbperm counts the permutations of the elements
of n taken r at a time. If n is a non-negative integer, it is interpreted in the same
way as a list of the first n integers.

• The count of permutations takes into account duplicates in n. In the case where
there are no duplicates, the count is given by the formula n!/(n−r)!.
• The function permute will compute the number of permutations.

2. Calling Sequence
choose(n)
choose(n, m
)
Parameters
n - list or set of objects or an non-negative integer
m - (optional) non-negative integer
Description
• If n is a list or set, then choose returns a list/set of the combinations of the list
elements. If n is a non-negative integer, it is interpreted in the same way as a
list of the first n integers.
• If m is given, then only combinations of size m are generated; otherwise, all
combinations are generated, including the empty combination, that is, the power
set is generated and converted to a sorted list. Note that duplicates in the
list n are taken into account.
• To calculate the number of combinations of n taken m at a time,
use combinat[numbcomb].
• The command with(combinat,choose) allows the use of the abbreviated form of
this command.
EXPERIMENT NUMBER: 10
Objective: Birthday problem.

Description: Since there are 365 days in the year, the probability of any two
people not having the same birthday is 364/365, the probability of a third person
having a different birthday than the other two people is 363/365, and so on. Thus,
in a room containing 23 people, the probability of no two people sharing the same
birthday will be:

364/365⋅363/365⋅...⋅(365−22)/365 = 364⋅363⋅...⋅(365−22)/36522

=365⋅364⋅363⋅...⋅343/36523=≈0.5 or 50%.

If this is the probability of no one having the same birthday, then the probability of
someone sharing a birthday is simply 1−0.5=0.5 or 50%.
EXPERIMENT - 11
Objective: Probability Simulations: Poker Hands problem.
Description: In one version of poker, Each player gets a five-card hand of
cards from a standard deck. Here are a few types of poker hands:
Full House: A hand consisting of 3 cards of the same denomination and
2 cards of same denomination (i.e. 3 of a kind and a pair).
Pair- A hand consisting of exactly one pair of cards with the same
denomination.
What is the probability of obtaining each of the above poker hands?
with(combinat, randcomb);
cardDeck(Ac, Ah, As, Ad, Kc, Kg, Kd, Kd, Qc,Qh ,Os, Qd, Je, Jh, Js,
Jd, seq(i.c,i=2..10), seq(i.h, i=2..10), seq(i.d,i=2..10), seq(i.s, i=2..10)};
randcomb(cardDeck, 5);
randcomb(card Deck, 2);
where Ah stands for ace of hearts. Od stands for Queen of diamonds.
and so forth.
Question: Simulate each game 20 times and keep track of your results in
the following tables
Full House
Trial 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Full House YNNYNYNNN N Y N N N N N N N N N
Total number of full house 4
Question 2: Find the empirical probability of obtaining a full house.
> 4/20
EXPERIMENT -12
Objective: Baseball best-of-5 series: Experimental probabilities
Description: The team A and team B are playing a best of 5 series. This means
that which ever team is the first to win 3 games is the winner of the series. Let's
first suppose that both teams are evenly matched. Before doing any calculations,
use your intuition to answer the following questions:
What is the probability that the A will sweep the B?
- Is the series most likely to end in 3.4 or 5 games?
-On average, how long do you expect the series to last?

We'll use Maple to help us simulate this best-of-5 series. The script is as follows,
where n = 2 and k=5.
randomize( );
randseries :=proc(n, k)
local i;
RETURN(map(rand(1..n),[seq(i,i=1..k) )
end proc;

Randseries := proc(n, k) local i ; RETURN (map(rand(1..n), [seq(i, i:=1..k) ]))


end proc
> randseries(2, 5)
[2, 2, 1, 1, 2]

Let A = 1 and B =2. Note that the series doesn't necessarily go to 5 games; if B
sweeps the A (i.e, any sequence that begins with 222) then the series is over in 3
games.

Question 1: Execute the procedure 20 times and record your results in the
following:
#games needed 3 4 5
A win 2 4 4
B win 2 4 4
Question 2: What is the experimental probability that the A will sweep the series?
>(2+4+4)/20
EXPERIMENT - 13
Objective: Baseball: Binomial Probability
Description: Assume that a player A gets a hit with probability 1/3. What is the
probability that in 100 plate appearances, A gets exactly 33 hits? Without doing
any calculations, provide an educated guess.
The following procedure calculates the probability that Junior gets on base exactly
k times in n attempts if he always gets a hit with probability p.
> with(combinat,numbcomb);
> prob:=proc(n,k,p)
numbcomb(n,k)*p^k*(1-p)^(n-k)
end proc;
Use the “prob” procedure to determine the probability that A gets on base exactly
33 times in 100 plate appearances.
What is the probability that in 100 plate appearances Junior gets on base between
31 and 35 times?
Use the following to calculate this probability.
> sumprob:=proc(n,p)
sum(‘numbcomb(n,k)*p^k*(1-p)^(n-k)’, ’k’=31..35);
end proc;
EXPERIMENT - 14
Objective: Basketball: One and One
Description: When a player is fouled in the game of basketball he or she
sometimes gets what’s called a “1-and-1 free-throw”. This means if the player
makes the shot, he/she scores a point and gets to shoot again. If the second basket
is made, the player scores an additional point. On the other hand, if the player
misses the first shot, he/she gets 0 points and does not get to try again.

1) Suppose that a player “A” is a pretty good free-throw shooter – he’s known to
make 60% of the shots that he attempts. When “A” goes to the line for a 1-and-1, is
he most likely to score 0, 1, or 2 points?

2) We’ll use Maple to simulate this problem. The following code simulates this
situation 30 times. What is an appropriate choice for n ? k ?

>oneandone:=proc(n,k)
local i, l;
randomize(); for l from 1 to 30 do:
print((map(rand(1..n),[seq(i,i=1..k)])));
end do;
end proc;

You might also like