Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in this code the equation is hard coded i want to change this code like user can give any kind of equation like that:- (code

image text in transcribed

in this code the equation is hard coded i want to change this code like user can give any kind of equation like that:-

image text in transcribed

(code is the secant method.)

i want the code not suggestion do like this.

written form of code:

import math N=int(input("Enter the no. Of Iterations : ")) TOL=float(input("Enter the Error Tolerance : ")) a=input("Enter the first initial approximation: ") a=int(a) b=input("Enter the second initial approximation: ") b=int(b) #------------------------Processing Section-----------------# xn=b x0=a x1=b fx0=4*x0 + math.sin(x0) - math.exp(x0) fx1=4*x1 + math.sin(x1) - math.exp(x1) for k in range(2,N+2): xp=xn xn=x1 - (fx1*(x1-x0))/(fx1-fx0) fxn=4*xn + math.sin(xn) - math.exp(xn) err = abs(xn-xp)/abs(xn) print("After",k-1,"iteration the approximate root=",xn) print("f(x)=",fxn," Error=",err) if(fxn break else: x0=x1 fx0=fx1 x1=xn fx1=fxn

if(err print("The desired accuracy achieved; Solution converged") else: print("The no of iterations exceeded the maximum limit");

what specification u need i just want the user will give equation which is hardcoded means in program equation is already given i want changes like that.

#- import math N=int(input("Enter the no. of Iterations : ")) TOL=float(input("Enter the Error Tolerance : ")) a=input("Enter the first initial approximation:") a=int(a) b=input("Enter the second initial approximation: ") b=int(b) --Processing Section-- xn=b x@=a x1=b fx0=4*x + math.sin(x0) - math.exp(x0) fx1=4*x1 + math.sin(x1) - math.exp(x1) for k in range(2,N+2): xp=xn xn=x1 - (fx1*(x1-x))/(fx1-fxo) fxn=4*xn + math.sin(x) math.exp(xn) err = abs(xn-xp)/abs(xn) print("After", k-1, "iteration the approximate root=",xn) print("f(x)=", fxn," Error=", err) if(fxn

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

Students also viewed these Databases questions

Question

How do public policy makers use the results of consumer research?

Answered: 1 week ago

Question

16.6 Outline the three waysto obtain union recognition.

Answered: 1 week ago