Question

Homework 4 - False Position Find the zeros of the function f(x) within the interval (-4, 6) using the False Position method w

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

clc
clear all
close all
x=linspace(-4,6,100000);
y=fun(x);
plot(x,y);
disp('Roots are');
r=falsepos(@fun,-4,-1,1e-17,7)
r=falsepos(@fun,-1,6,1e-17,200)
function y=fun(x)
y=sin(2*pi*x/5)+exp(x/5);
end
function [root,errs, iter]=falsepos(func,lb,ub,err_max,iter_max)
errs=[];
root=[]; func_val=[]; err=[]; numIter=[]; % Output set to empty matricesinitially
exitFlag=1;

if(nargin)==3 % check if last two arguments have been passed or not
err_max=0.0001; % assign the default values
iter_max=50;
elseif (nargin)==4 % check if last argument have been passed or not
iter_max=500; % assign the default values
elseif (nargin)<3 || nargin>5 % if less than three or more than five arguments have been passed, raise an error and return
warning('Insufficient arguments passed!');
return;
  
end

if func(lb)*func(ub)>0 % check if the function value at initial points are not same sign, raise and error return
disp('Probelm with interval signs. Try again!');
exitFlag=-1;
return;
elseif (lb>ub) % check if x_min<x_max i.e. intervals ae not in same order,raise and error return
disp('Probelm with interval size. Try again!');
exitFlag=-1;
return;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAIN BODY OF FUNCTION:

n=0; % number of iteartions computed yet
func_x_max=func(ub); func_x_min=func(lb);

c=lb-((ub-lb)/(func_x_max-func_x_min))*func_x_min; % find the next guess point
err = abs(ub-lb); % take initial error estimate

% Uncomment the following line and line 72 to see result in each iteration
% fprintf('Iteration x_min x_max Root Error estimated ');
while err > err_max && n<iter_max % loop will continue as long as this criteria holds true
n=n+1; % iteration number
if func(lb)*func(c)<0 % select the interval of root
ub = c;
  
else % select the interval of root
lb = c;
end
func_x_max=func(ub); func_x_min=func(lb);
  
c = lb-((ub-lb)/(func_x_max-func_x_min))*func_x_min; % find the next guess point
err = abs(ub-lb)/abs(ub);
errs(n)=err;
% Uncomment the following line to see result in each iteration
% fprintf('%d %3.6f %3.4f %3.4f %3.8f ',n,lb,ub,c,err); % display the iteration result
end
root=c;
ea=err;
iter=n;
end

- 5 x Pradeep EDITOR PUBLISH VIEW do Es C E Search Documentation > insert E. fx for Comment % 92% Indent 1 - Figure 1 - 6 x B

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Homework 4 - False Position Find the zeros of the function f(x) within the interval (-4,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y =...

    Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y = sin(x) from x = 0 to 21. 12) Plot the functions y = x2 z = x2 + 2x + 1 from x = 0 to 2 on the same graph. Scripts: Input and Output 13) Write a script (M-file) to read in a message at the command line using the MATLAB input function and then display the message to the Command Window using...

  • Using MATLAB (a) Find the Fourier series for 25 { O if 1 r<O 1-2 if 0<H<1 f(x) defined on the interval -1<rs...

    Using MATLAB (a) Find the Fourier series for 25 { O if 1 r<O 1-2 if 0<H<1 f(x) defined on the interval -1<rs1. T-2 (b) Using MATLAB, plot the first 20 terms and the first 200 terms of the Fourier series in the interval -3< r<3, In order to do this, the r-interval should be divided into 6001 cqually spaced points by making use of the MATLAB command linspace. (a) Find the Fourier series for 25 { O if 1...

  • (a) Find the Fourier series for 25 { O if 1 r<O 1-2 if 0<H<1 f(x) defined on the interval -1<rs1. T-2 (b) U...

    (a) Find the Fourier series for 25 { O if 1 r<O 1-2 if 0<H<1 f(x) defined on the interval -1<rs1. T-2 (b) Using MATLAB, plot the first 20 terms and the first 200 terms of the Fourier series in the interval -3< r<3, In order to do this, the r-interval should be divided into 6001 cqually spaced points by making use of the MATLAB command linspace. (a) Find the Fourier series for 25 { O if 1 r

  • (a) Find the Fourier series for 25 { O if 1 r<O 1-2 if 0<H<1 f(x) defined on the interval -1<rs1. T-2 (b) U...

    (a) Find the Fourier series for 25 { O if 1 r<O 1-2 if 0<H<1 f(x) defined on the interval -1<rs1. T-2 (b) Using MATLAB, plot the first 20 terms and the first 200 terms of the Fourier series in the interval -3< r<3, In order to do this, the r-interval should be divided into 6001 cqually spaced points by making use of the MATLAB command linspace. (a) Find the Fourier series for 25 { O if 1 r

  • 3. Consider the function f(x) = cos(x) in the interval [0,8]. You are given the following 3 point...

    3. Consider the function f(x) = cos(x) in the interval [0,8]. You are given the following 3 points of this function: 10.5403 2 -0.4161 6 0.9602 (a) (2 points) Calculate the quadratic Lagrange interpolating polynomial as the sum of the Lo(x), L1(x), L2(x) polynomials we defined in class. The final answer should be in the form P)a2 bx c, but with a, b, c known. DELIVERABLES: All your work in constructing the polynomial. This is to be done by hand...

  • MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the...

    MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the following math function 3 o-0.47x The input to the function is x and the output is y. Write the function such that x can be an array (use element-by-element operations) (15 pts) Use the function in (a) the command window to calculate y(-2) and y(5) (b) a script file HW7P2.m to determine y(x) for 0.001 Sx S 10 with 1000 points. Hint: Use the...

  • Write a MATLAB script to plot the function of f(x) given by: Write a MATLAB script...

    Write a MATLAB script to plot the function of f(x) given by: Write a MATLAB script to plot the function of f(x) given by: f(x) = integral x^2 - pi^2/4 x > pi/2 8 * cos x -pi/2 lessthanorequalto x lessthanorequalto pi/2 pi^2/4 - x^2 x < -pi/2

  • Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to...

    Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to symbolically compute the derivative of ln(x) on the interval from -5 to 5, containing 100 data points. Your script file should output a plot of the derivative of ln(x) (taken from your function) vs x. Use a line with circular markers for the plot and include a grid and appropriate labels. The user-defined function should 1. Receive a single x value as input. 2....

  • 6. Use Matlab to find the point(s) of intersection (if any) between the functions f()10sin(2 5) a...

    6. Use Matlab to find the point(s) of intersection (if any) between the functions f()10sin(2 5) and g(x)-6r-4, accurate to two decimal places. Write down the Matlab commands to produce the x-vector, the vectors representing the f- and g-values and the plot of the graphs. 7. Use Matlab to find the minimum (accurate to two decimal places) of the function in the interval (0,π). 6. Use Matlab to find the point(s) of intersection (if any) between the functions f()10sin(2 5)...

  • Find the minimum of the given function f(x) using the Golden Section Search at an interval 2,3.25...

    can you please show hand calculations Find the minimum of the given function f(x) using the Golden Section Search at an interval 2,3.25]. Show hand calculated solutions, fill in the table, and use three decimals. Regarding MATLAB, plot the function and solve for the extremum using a built-in function. f(x) 3cos(a) sin(a) 2(2) 3.525 | -2:408|1o311 Find the minimum of the given function f(x) using the Golden Section Search at an interval 2,3.25]. Show hand calculated solutions, fill in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT