Question

In: Computer Science

PLEASE USE PYTHON CODE 7. determine the two roots of sinx+3cosx-2 =0 that lie in the...

PLEASE USE PYTHON CODE

7. determine the two roots of sinx+3cosx-2 =0 that lie in the interval (-2,2). use the Newton- Raphson method and solve by the secant formula

Solutions

Expert Solution

# Program to find root of an equations using secant method

# function takes value of x

# and returns f(x)

import math

def f(x):

# we are taking equation as sinx+3cosx-2

f = math.sin(x)+3*math.cos(x)-2

return f;

def secant(x1, x2, E):

n = 0; xm = 0; x0 = 0; c = 0;

if (f(x1) * f(x2) < 0):

while True:

# calculate the intermediate value

x0 = ((x1 * f(x2) - x2 * f(x1)) /

(f(x2) - f(x1)));

# check if x0 is root of

# equation or not

c = f(x1) * f(x0);

# update the value of interval

x1 = x2;

x2 = x0;

# update number of iteration

n += 1;

# if x0 is the root of equation

# then break the loop

if (c == 0):

break;

xm = ((x1 * f(x2) - x2 * f(x1)) /(f(x2) - f(x1)));

if(abs(xm - x0) < E):

break;

print("Root of the given equation =", round(x0, 6));

print("No. of iterations = ", n);

else:

print("Can not find a root in the given inteval");

# Driver code

# initializing the values

x1 = 0;

x2 = 90;

E = 0.0001;

secant(x1,x2, E);

Please refer the snap given below for indentation:



Related Solutions

use Java The two roots of a quadratic equation ax^2 + bx + c = 0...
use Java The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac)) / (2a) and r2 = (-b - sqrt(b^2 - 4ac)) / (2a) b^2 - 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no...
PLEASE USE PYTHON CODE 7. Use Newton's method to find the polynomial that fits the following...
PLEASE USE PYTHON CODE 7. Use Newton's method to find the polynomial that fits the following points: x = -3, 2, -1, 3, 1 y = 0, 5, -4, 12, 0
MATLAB Coding. Please answer with respected Matlab code format HW 2_5 Determine the two roots of...
MATLAB Coding. Please answer with respected Matlab code format HW 2_5 Determine the two roots of f(x) = 2x cos(2x) − (x − 2)^2 , using falsepos.p, accurate to 3 sig figs. Plot these points on the graph with a star marker.
PLEASE USE PYTHON CODE 2. Find the smallest positive (real) root of x^3-3.23x^2-5.54x+9.84 = 0 by...
PLEASE USE PYTHON CODE 2. Find the smallest positive (real) root of x^3-3.23x^2-5.54x+9.84 = 0 by the method of bisection
A= 1 0 -7 7 0 1 0 0 2 -2 10 -7 2 -2 2...
A= 1 0 -7 7 0 1 0 0 2 -2 10 -7 2 -2 2 1 Diagonalize the matrix above. That is, find matrix D and a nonsingular matrix P such that A = PDP-1 . Use the representation to find the entries of An as a function of n.
1. Please use Python 3 programing. 2. Please share your code. 3. Please show all outputs....
1. Please use Python 3 programing. 2. Please share your code. 3. Please show all outputs. Create a GUI Calculator with the following: Title : Calculator Label and Entry box for 1st Number Label and Entry box for 2nd Number Buttons for *, /, +, - Label for result and Displaying the result
Use python programming to write this code and provide a screen short for the code. 2....
Use python programming to write this code and provide a screen short for the code. 2. Write a function that takes one argument (a string) and returns a string consisting of the single character from that string with the largest value. Your function should contain a for loop. You can assume that the input to your function will always be a valid string consisting of at least one character. You can assume that the string will consist only of lower-case...
Updated! Python Code 4. Enhanced transmission method Use the same probabilities ?0 ; ?0; and ?1...
Updated! Python Code 4. Enhanced transmission method Use the same probabilities ?0 ; ?0; and ?1 as before and consider the following experiment: p0=0.6 ; e0=0.05; e1=0.03 • You create and transmit a one-bit message S as before. In order to improve reliability, the same bit “S” is transmitted three times (S S S) as shown in Figure 2. • The received bits “R” are not necessarily the same as the transmitted bits “S” due to transmission errors. The three...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please show all outputs. Instructions: Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18   List as Stack Code: """...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: a. def count_character(text, char): """ Count the number of times a character occurs in some text. Do not use the count() method. """ return 0 b. def count_sentences(text): """...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT