Question

In: Advanced Math

Write a script that uses the function below to find root brackets for ?(?) = cos(ex)...

Write a script that uses the function below to find root brackets for ?(?) = cos(ex) + sin(?), between ? = 0 ??? ? = ? with ns=100. Plot the output by first plotting the function and then plotting ‘*’ at each bracket point (on the x-axis). You may either give the plot() function two sets of inputs, or you can use hold on ... hold off to add plots to your figure.

function xb = incsearchv(func,xmin,xmax,ns)

Solutions

Expert Solution


clear all
close all
%function for which root have to find
func=@(x) cos(exp(x))+sin(x);
fprintf('function for which root have to find f(x)=')
disp(func)
%upper and lower limit
x0=0; x1=pi;
xx=linspace(x0,x1,1000);
yy=func(xx);
plot(xx,yy)
xlabel('x')
ylabel('f(x)')
title('x vs. f(x) plot')
[root]=incsearchv(func,x0,x1,100);
hold on
plot(root,func(root),'r*')

%Matlab function for Bisection Method
function [root]=incsearchv(fun,x0,x1,maxit)
if fun(x0)<=0
    t=x0;
    x0=x1;
    x1=t;
end
fprintf('\nRoot using Bisection method\n')
%f(x1) should be positive
%f(x0) should be negative
k=10; count=0;
while k>5*10^-10
    count=count+1;
    xx(count)=(x0+x1)/2;
    mm=double(fun(xx(count)));
    if mm>=0
        x0=xx(count);
    else
        x1=xx(count);
    end
    err(count)=abs(fun(x1));
    k=abs(fun(x1));
    if count>=maxit
        break
      
    end
    %
end
fprintf('\tAfter %d iteration root using Bisection method is %f\n',count,xx(count))
root=xx(end);
end

            %%%%%%%%%%%% End of Code %%%%%%%%%%%%%


Related Solutions

To find a positive root for , write a MATLAB script file that uses Bisection method....
To find a positive root for , write a MATLAB script file that uses Bisection method. Choose any initial value that is needed. Use absolute relative approximate error to be less than 0.01. Your code should report the number of iteration and the value of x.
Consider the function below. f(x) = ex 3 + ex Find the interval(s) where the function...
Consider the function below. f(x) = ex 3 + ex Find the interval(s) where the function is decreasing. (Enter your answer using interval notation. If an answer does not exist, enter DNE.) Find the local maximum and minimum values. (If an answer does not exist, enter DNE.) Find the inflection point. (If an answer does not exist, enter DNE.) Consider the function below. f(x) = x2 x2 − 16 Find the interval(s) where the function is increasing. (Enter your answer...
Using the bisection method, find the root of the following function: f(x)=cos(2x) - x Use the...
Using the bisection method, find the root of the following function: f(x)=cos(2x) - x Use the following initial values: xl=0 and xu=2 NOTE: Perform only 3 iterations.
PYTHON: Write a script that imports the functions in the module below and uses all of...
PYTHON: Write a script that imports the functions in the module below and uses all of the functions. import math def _main():     print("#" * 28, "\n", "Testing...1, 2, 3...testing!\n", "#" * 28, "\n", sep="")     f = -200     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     f = 125     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     c = 0     print("{:.2f} C is {:.2f} F".format(c, c2f(c)))     c = -200     print("{:.2f} C is {:.2f} F".format(c, c2f(c))) def f2c(temp):     #Converts Fahrenheit tempature to Celcius     if temp <...
Question #11. Write a script that uses the menu function to prompt the user to select...
Question #11. Write a script that uses the menu function to prompt the user to select the current day of the week. Then use the menu function to prompt the user to select their favorite day of the week. Print a message telling the user how many days it will be until their favorite day. The output must include the current day, the favorite day, and the number of days until the favorite day. Debug your programming by running it...
write a function to determine the square root of a number. The square root of a...
write a function to determine the square root of a number. The square root of a number can be approximated by repeated calculation using the formula NG = 0.5(LG + N/LG) where NG stands for the next guess and LG stands for the last guess. The loop should repeat until the difference between NG and LG is less than 0.00001. Use an initial guess of 1.0. Write a driver program to test your square root function. I WANT THIS PROGRAM...
Use the Newton’s method to find the root for ex+1 = 2 + x, over [−2,...
Use the Newton’s method to find the root for ex+1 = 2 + x, over [−2, 2]. Can you find a way to numerically determine whether the convergence is roughly quadratic using error produced at each iteration? Include your answers as Matlab code comments
Use the False Position method to find a guess of the root of f(x) = cos(x2...
Use the False Position method to find a guess of the root of f(x) = cos(x2 ) with lower and upper bounds of 0 and 2, respectively. Then, narrow the interval and find a new guess of the root using False Position. What is your relative approximate error? a. 8.47% answer b. 12.45% c. 0.112 d. 0.243 e. None of the above Please provide complete solution how the answer is a thumbs up for correct and neat solution! step by...
Write a script le using conditional statements to evaluate the following function, assuming that the scalar variable x has a value. The function is Y = ex+1 fo
Write a script le using conditional statements to evaluate the following function, assuming that the scalar variable x has a value. The function isY = ex+1 for x < -1, y = 2 + cos(πx) for -1 ≤ x ≤ 5, and y = 10(x - 5) + 1 for x ≥ 5. Use your le to evaluate y for x = -5, x = 3, and x = 15, and check the results by hand.
Ex. 1.Create a Python script . Write a program that goes through a tupple of numbers...
Ex. 1.Create a Python script . Write a program that goes through a tupple of numbers representing the temperatures taken at regular intervals in a day, at least 6 of them. The program should store this tupple in a variable, and then computing the average temperature. For that, use a for loop going over the temperature and adding all the values to a variable sum, initialized as 0. Then at the end, divide the sum by their count, and output...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT