



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The course covers important and advance elements of C and C plus plus programming language. This course provides the student with the skills required to design, code, and test and execute programs of simple to intermediate complexity. It includes: Maze, Problem, Boundary, Obstacles, Moveable, Region, Directions, Time, Coordinates, Cell
Typology: Exercises
1 / 5
This page cannot be seen from the preview
Don't miss anything!
th
Objective A rat is trapped in a maze at a preset starting position and needs to get to his cheese. The cheese is present at a predefined finish point. Write a program to help the rat get to his cheese by finding a path from a start position to a finish position.
Guidelines
Have a boundary around your maze and fill it up with all *s. The inner walls (obstacles) are represented by all Xs and the moveable region is represented by all 0s. The rat cannot go outside the boundary wall.
The rat can move in four directions at any point in time (R: right, L: left, U: up, D: down). The rat cannot move diagonally. HaveaMxN matrix as the maze,
Checking right means adding {0,1} to the current coordinates.
Checking left means adding {0,-1} to the current coordinates.
Checking up means adding {-1,0} to the current coordinates.
Checking down means adding {1,0} to the current coordinates.
The rat will start off at the last row and the last column i.e. starting point = [M-1, N- 1].
From there, it tries to move to a cell which is free. A cell is free if it has 0 in it.
It tries all the 4 options one-by-one till it finds an empty cell. If it finds one, it moves to that cell and marks it with a 1 (i.e. it has visited it once). Then it moves ahead from that cell to an appropriate direction (R, L, U, and D).
If at a particular cell, it runs out of all the 4 options (that is it cannot move either right, left, up or down), then it needs to backtrack. It backtracks till a point where it can move ahead and be closer to the finish.Finish is defined as the [M-1, 0] cell.
If it reaches the exit point, it gets the cheese.
Exit Start
Solving system of linear equation
Objective Write a C program that solves system of linear equation using Gauss Elimination method. Guidelines System of linear equation:
This can be written in matrix form as Ax=b , where A is the coefficient matrix of variables, x is the vector of variables (x,y,z) and b is the vector of values on RHS of the above system of equation. 4 8 4 2 1 − 4 3 − 1 2
Since x is the vector of unknown so we need to solve Ax=b to find x. There are different techniques available to find x. For example Cramer's rule and x=A-1b Gauss Elimination Method: (Lal, 2007) Gauss elimination method was developed by 19th Century scientist Carl Fridrich Gauss (1809).(gauss_wiki, 2010)In this method finding A-1^ is not required. Matrix A is converted into an upper triangle matrix with all zeros in the lower matrix. Gauss Elimination is divided into two parts. First part is converting matrix A into upper triangle and second part is using back substitution to find values of variables
Example1: Use Gaussian elimination to solve the system of equations: Solution: Perform this sequence of Elementary Row Operations (E.R.O.'s) on the augmented matrix. Set the pivot column to column 1. Get a 1 in the diagonal position (underlined):
Next, get 0's below the pivot (underlined):
Now, let pivot column = second column. First, get a 1 in the diagonal position:
Solution to system of linear equation: Depending on the matrix you can get three kinds of solutions. Solution 1: see example 1, in this example you get unique solution to every variable. In this case you have to tell user that solution to this system is unique and show the solution to the user.
Solution 2: let’s look at another example.
2 𝑥 + 3𝑦 = 5 4 𝑥 + 6𝑦 = 10 When we apply Gaussian elimination on this system we get 2 3 4 6
Now if you want to apply back substitution on this you will not get a unique solution. You need to identify this case and have to tell user that this system does not have a unique solution.
Solution 3: Third case is the one when you don’t get any solution. For example 𝑥 + 𝑦 = 6 4 𝑥 + 4𝑦 = 10 When we apply Gaussian elimination on this system we get 1 1 4 4
In this case you cannot get any solution.
gauss_wiki. (2010, 12 21). Gaussian_Elimination. Retrieved 12 21, 2010, from wikipedia: http://en.wikipedia.org/wiki/Gaussian_elimination
Lal, A. K. ( 2007, 09 12).. Retrieved december 21, 2010, from http://nptel.iitm.ac.in/courses/Webcourse-contents/IIT- KANPUR/mathematics-2/node18.html
mat10. (n.d.). Retrieved December 21, 2010, from mathonweb: http://mathonweb.com/help/backgd3e.htm