Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Given f(x) = ex + log10(sin(x))-3. 14-0, x in radians The following VBA progr

ID: 3281851 • Letter: 5

Question

5. Given f(x) = ex + log10(sin(x))-3. 14-0, x in radians The following VBA program applies the Newton-Raphson method ( n·x f VF(x) to find the root of this equation. Instead of the actual derivative, approximates the derivative f' (%) as (f(x +1x10-4)-f(x)/104 . The initial guess, x0 2, is hard-wired in the program. Let the maximum number of iterations 150, and the tolerance on the approximate error 10. For each iteration output to your spreadsheet the iteration number, the current value of x, ffx), and the approximate, EA. Specify parameters and integration limits in your main sub. Perform the Newton-Raphson method in a subordinate sub. Use a Do While loop to handle the iterations and output from the called sub. Put fx) and fe) in separate functions. Use an Excel library finction for log 10(x) and use Option Explicit The following program contains 10 mistakes. Find them and run the program to solve the problem Option Explicit Sub E2P3b0 Dim x as double , x0 as double, xn as double, tol as double, ea as double Dim it, itmax as integer 2 it-0 itmax = 1 50 tol le-7 ea = 2*tol Do While it

Explanation / Answer

A similar MATLAB code executed gives the results:

Code:

clc;clear all;close all;
f=@(x) (exp(x)+(log(sin(x)))./(log(10))-3.14);
g=@(x) (((exp(x+(10^(-4)))+(log(sin(x+(10^(-4)))))./(log(10))-3.14)-(exp(x)+(log(sin(x)))./(log(10))-3.14))./(10^(-4)));
x(1)=2;
x(2)=x(1)-((f(x(1)))./g(x(1)));
i=2;
imax=150;
while i<imax && f(x(i))>(10^(-7))
x(i+1)=x(i)-((f(x(i)))./g(x(i)));
i=i+1;
end
functionval=f(x);

Results:

Thus, the solution to the given function f(x)=0 is x=1.56381636 (approximately)

Iteration x(i) f(x(i)) 0 2 4.207762061 1 1.414827972 0.97047447 2 1.182893019 0.09027502 3 1.156660926 0.000941162 4 1.156381677 1.41E-07 5 1.156381636 5.56E-12
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote