Question: In the below code of a customtkinter GUI application of Regula Falsi Numerical Method, kindly update the part where it updates the equation so it

In the below code of a customtkinter GUI application of Regula Falsi Numerical Method, kindly update the part where it updates the equation so it accepts cos, sin equations as well for e.g. (2*math.cos + 1).

Kindly run the code and make it more efficient hence then it will take all kind of equations that involves cos, sin as well.

Code:

from tkinter import * import customtkinter import math customtkinter.set_appearance_mode("dark") customtkinter.set_default_color_theme("dark-blue") root = customtkinter.CTk() root.geometry("700x600") root.title("Implementation of Numerical Methods") def RegulaFalsi(): def f(x): return x*x - 1 def RF(x0,x1,e): Iteration = 1 condition = True while condition: x2 = x0 - (x1-x0) * f(x0)/( f(x1) - f(x0) ) RF_Iterations_Result.set('Iteration-%d, X2 = %0.6f and f(X2) = %0.6f' % (Iteration, x2, f(x2))) root.update_idletasks() if f(x0) * f(x2) < 0: x1 = x2 else: x0 = x2 Iteration = Iteration + 1 condition = abs(f(x2)) > e RegulaFalsi_Root_Result.set(' Required Root using Regula Falsi Method is: %0.8f' % x2) root.update_idletasks() eq = equation1.get() x0 = x0_entry1.get() x1 = x1_entry1.get() e = e_entry1.get() f = lambda x: eval(eq) x0 = float(x0) x1 = float(x1) e = float(e) if f(x0) * f(x1) > 0.0: print('Not in range') else: RF(x0,x1,e) tabView = customtkinter.CTkTabview(root) tabView.pack(padx = 20, pady = 60) tabView.add("Regular Falsi") frame = customtkinter.CTkFrame(master=root) frame.pack(pady=5, padx=5, fill="both", expand=True) RegulaFalsi_Root_Result = StringVar() RF_Iterations_Result = StringVar() equation1 = customtkinter.CTkEntry(tabView.tab("Regular Falsi"), placeholder_text="eq") equation1.pack(pady=12, padx=10) x0_entry1 = customtkinter.CTkEntry(tabView.tab("Regular Falsi"), placeholder_text="x0") x0_entry1.pack(pady=12, padx=10) x1_entry1 = customtkinter.CTkEntry(tabView.tab("Regular Falsi"), placeholder_text="x1") x1_entry1.pack(pady=12, padx=10) e_entry1 = customtkinter.CTkEntry(tabView.tab("Regular Falsi"), placeholder_text="e") e_entry1.pack(pady=12, padx=10) button2 = customtkinter.CTkButton(tabView.tab("Regular Falsi"), command=RegulaFalsi, text="Regular Falsi") button2.pack(pady=12, padx=10) label4 = customtkinter.CTkLabel(tabView.tab("Regular Falsi"), textvariable = RF_Iterations_Result) label4.pack(pady=20, padx=20, fill="both", expand=True) label3 = customtkinter.CTkLabel(tabView.tab("Regular Falsi"), textvariable = RegulaFalsi_Root_Result) label3.pack(pady=20, padx=20, fill="both", expand=True) root.mainloop()

Step by Step Solution

3.55 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The provided code can be improved to accept equations with sin and cos functions using the sympy library Heres the updated version Python from tkinter import import customtkinter import math import sy... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!