Question

Exercise 4: (Computer Problem) Write a function to implement the following al- gorithm and use your algorithm to find the sol

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

ANSWER :

clear all
close all

%function for finding root
f=@(x) exp(x)+sin(x)-4;
a=1; b=2; tol=10^-10;

fprintf('function for the algorithm f(x)=')
disp(f)

fprintf('\t e_i \t e_i+1/e_i\t e_i+1/e_i^2\n')
i=0;fc=100; c=10;
while abs(fc)>tol
i=i+1;

fc=double(f(c));
err1=abs(fc);
c=double((b*f(a)-a*f(b))/(f(a)-f(b)));
if f(a)*f(c)<=0
b=c;
else
a=c;
end
err2=abs(f(c));
fprintf('\t%2.2e \t%2.2e \t%2.2e\n',err1,err2/err1,err2/err1^2)

end

OUT PUT :

function for the algorithm f(x)= C(x)exp(x)+sin(x)-4 ei e_i+1/e_i e_1+1/e i 2 2.20 +04 5.86e-06 2.661-10 1.29e-01 2.89e-01 2.

Add a comment
Know the answer?
Add Answer to:
Exercise 4: (Computer Problem) Write a function to implement the following al- gorithm and use your...
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
  • Problem 6 Implement a MATLAB function bisection.m of the form bisection (a, b, f, p, t)...

    Problem 6 Implement a MATLAB function bisection.m of the form bisection (a, b, f, p, t) function [r, h] Beginning of interval [a, b] % b End of interval [a, b] % f function handle y = f(x, p) % p: parameters to pass through to f % t User-provided tolerance for interval width a: At each step j = 1 to n, carefully choose m as in bisection with the geometric (watch out for zeroes!) Replace a, b by...

  • 4. (6pt) Use the inner product (f,g)f ds to determine the following. (a) Determine if the functio...

    i need help with this linear Algebra question 4. (6pt) Use the inner product (f,g)f ds to determine the following. (a) Determine if the function g(z) = z2-3x + 2 or h(x) = x2-2x + 1 is closest to the fl () is closest to the function f)2+2 on (b, Show that (1,2r - 1) is an orthogonal set (c) Beginning with the basis (1,2 1, 2 (d) Find an orthonormal basis for P2. (e) Find the least squares quadratic...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demo...

    MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demonstrates using instructor-provided and randomized inputs to assess a function problem. Custom numerical tolerances are used to assess the output. Simpson's Rule approximates the definite integral of a function f(x) on the interval a,a according to the following formula + f (ati) This approximation is in general more accurate than the trapezoidal rule, which itself is more accurate than the leftright-hand rules. The increased...

  • (a) (4 points) Fill in the blanks in the following MATLAB function M file trap so...

    (a) (4 points) Fill in the blanks in the following MATLAB function M file trap so that it implements the composilu trapezidul rulo, using a soquence of w -1,2, 4, 8, 16,... trapezoids, to approximatel d . This M file uses the MATLAB built-in function trapz. If 401) and y=() f(!)..... fr. 1)). 3= ($1, then the execution of z = trapz(x, y) approximates using the composite trapezoidal rule (with trapezoids). (Note that the entries of are labeled starting at...

  • Exercise 6: Given the table of the function f(x)-2" 2 X 0 3 2 f(x) 1 2 4 8 a) Write down the Newton polynomial...

    Exercise 6: Given the table of the function f(x)-2" 2 X 0 3 2 f(x) 1 2 4 8 a) Write down the Newton polynomials P1(x), P2(x), Pa(x). b) Evaluate f(2.5) by using Pa(x). c) Obtain a bound for the errors E1(x), E2(x), Es(x) Exercise 7: Consider f(x)- In(x) use the following formula to answer the given questions '(x) +16-30f+16f,- 12h a) Derive the numerical differentiation formula using Taylor Series and find the truncation error b) Approximate f'(1.2) with h-0.05...

  • Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any a...

    Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any arbitrary function f given an initial guess xo, an absolute error tolerance e and a maximum number of iterations max iter. Follow mynewton.m template posted in homework 2 folder on TritonED for guidance. You are not required to use the template. The function should return the approximated root ^n and the number of steps n taken to reach the solution. Use function mynewton.m to perform...

  • PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and...

    PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and my code for bag.cpp. Also I have provided errors from linux for bag.cpp. Please use that code and fix my errors please. Thank you The goal of assignment 3 is to reinforce implementation of container class concepts in C++. Specifically, the assignment is to do problem 3.5 on page 149 of the text. You need to implement the set operations union, intersection, and relative...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A*...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class. For more information, please read the wiki page of 15-puzzle problem at https://en.wikipedia.org/wiki/15_puzzle, and the wiki page of...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* s...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. Please include pictures that the code runs and shows the different states as it reaches goal state please. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class....

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