Need solution for question 5.6 using python?
#include <windows.h> // SetConsoleCursorPosition(HANDLE,COORD)
#include <conio.h> // _getch()
/**
* moves the console cursor to the given x/y coordinate
* @param x
* @param y
*/
void moveCursor(int x, int y)
{
COORD c = {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
int main()
{
// player data
int x = 3, y = 4;
char icon = 1;
// game state constants
const int RUNNING = 1, WIN = 2, LOST = 3, USER_QUIT = -1;
// game data
int width = 20, height = 15, input, state = RUNNING;
do
{
// draw the game world
moveCursor(0,0);
for(int row = 0; row < height; row++)
{
for(int col = 0; col < width; col++)
{
cout << '.';
}
cout << '\n';
}
// draw the player
moveCursor(x, y);
cout << icon;
// get input from the user (wait for one key press)
input = _getch();
// process input from the user
switch(input)
{
case 'w': y--; break; // move up
case 'a': x--; break; // move left
case 's': y++; break; // move down
case 'd': x++; break; // move right
case 27: state = USER_QUIT; break; // quit
}
// show the game state message
moveCursor(0, height+1);
switch(state)
{
case WIN: cout << "You WON! Congratulations!\n"; break;
case LOST: cout << "You lost...\n"; break;
}
}
while(state == RUNNING);
// user must press ESCAPE before closing the program
cout << "press ESCAPE to quit\n";
while(_getch() != 27);
return 0;
}
Need solution for question 5.6 using python? tation to within e, 5.11 Determine the real root...
l. Determine the real root(s) off(x)--5xs + 14x3 + 20x2 + 10x a. Graphically on a graph paper. b. Using Bisection method c. Using False Position method to determine the root, employing initial guesses of x-2 d. Using the Newton Raphson methods to determine the root, employing initial guess to determine the root, employing initial guesses ofxn-2 and Xu-4 and Es= 18%. and r 5.0 andas answer. 1%. was this method the best for these initial guesses? Explain your xo--l...
Numerical methods. Need help please 2. Determine the real rot of f(x)--26+85x-91x+44x -8xx a. Graphically. b. Using bisection method. Employ initial guesses of x-O and xu 1 and iterate until the approximate error falls below 10%. Perform the same computation using false-position method. Iterate until the approximate error falls below 0.2%. c.
6.5 Employ the Newton-Raphson method to determine a real root for 4x20.5 using initial guesses of (a) 4.52 f(x) 15.5x Pick the best numerical technique, justify your choice and then use that technique to determine the root. Note that it is known that for positive initial guesses, all techniques except fixed-point iteration will eventually converge. Perform iterations until the approximate relative error falls below 2 %. If you use a bracket- ing method, use initial guesses of x 0 and...
using matlab code please 5.2 Determine the real root of f(x) = 5x? - 5x2 + 6x-2: a. Graphically. b. Using bisection to locate the root. Employ initial guesses of x= 0 and xy = 1 and iterate until the estimated error &, falls below a level of Es = 10%.
(la) Determine the root of the x – ez* + 5 = 0 using the Newton-Raphson method with equation initial guess of xo = 1. Perform the computation until the percentage error is less than 0.03%. (1b) Employ bisection method to determine the root of the f(x)=x* – 3x + 7 =0) using equation two initial guesses of x; =-2.1 and x;, =-1.8 . Perform three iterations and calculate the approximate relative error for the third iteration. What is the...
2) (15 points) a) Determine the roots of f(x)=-12 – 21x +18r? - 2,75x' graphically. In addition, determine the first root of the function with b) bisection and c) false-position. For (b) and (c), use initial guesses of x, =-land x, = 0, and a stopping criterion of 1%. 3) (25 points) Determine the highest real root of f(x) = 2x – 11,7x² +17,7x-5 a) Graphically, b) Fixed-point iteration method (three iterations, x, = 3) c) Newton-Raphson method (three iterations,...
Problem 2 Determine the real roots of f(x)=-25 +82.x - 90x2 +44x-8x +0.7.x a) Graphically b) Using bisection method to determine root (0.5, 1.0) 6 = 0.1 c) False position method, Use initial guesses of x=0.5 and x. -1.0 Compute the estimated errore, with stopping criteria 1%
2. A comparative problem: Determine the highest real root of flx)-2x3-11.7x'+17.7x-5 You will achieve this by performing 3 iterations of the following methods. In each case, calculate the approximate relative error at each iteration (a) The bisection method with starting guesses x 3 and u-4 (b) New Raphson method using Xo 3 as a starting guess. (c) Fixed point iteration usingx 3 as a starting guess but make sure that the method will work (see question 1.b above). (d) Which...
3. Find the positive root of In(x²) = 0.7 20-points a) Using three iterations of the bisection method with initial guesses of Xi on method with initial guesses of x = 0.5 and Xu 2, and b) Using three iterations of the Secant method, with the same initial guesses as in .
Letermine the real root of f(x)= - 8x + 56x4x-7 a) Grophically to determine the root to b) using bsection &a=2%. Employ initial guesses of and xu = 8 xe=3 c) using the false-position method to determine the root to a 25% . Employ the some intials as in (b).