Question

(a) Write a code that uses to approximate f(), where f(x) tan-1z and a-v2. (Note (v2 Output k, h,r,e. Here k is the iteration

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

clc;
clear all;
f=@(x)atan(x);
x=sqrt(2);
k=1;
h=0.5;
err=0.1;
disp('________________________________________________')
disp('k h r e')
disp('________________________________________________')
while(err>1e-10)


r=(-f(x+2*h)+8*f(x+h)-8*f(x-h)+f(x-2*h))/(12*h);
err=abs(r-(1/3));


fprintf('%f %f %f %e ',k,h,r,err)
R(k)=err;
h=h/2;
k=k+1;

end


for j=1:k-2
Order(j)=log2(R(j)/R(j+1));
end
disp('Rate of Order')
Order'

1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 Rate of Order 0.500000 0.250000 0.125000 0.062500 0.031250 0.0

Add a comment
Know the answer?
Add Answer to:
(a) Write a code that uses to approximate f(), where f(x) tan-1z and a-v2. (Note (v2...
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
  • Write MATLAB code g(x)=x+a*f(x) f(x)=(e^x)+(x^2)-x-4 function f(x) is stored in fogp1.m (c) (1) Create a file...

    Write MATLAB code g(x)=x+a*f(x) f(x)=(e^x)+(x^2)-x-4 function f(x) is stored in fogp1.m (c) (1) Create a file gopgi.m to calculate the function glir, a) (see Preparation, ex. 7c) function [y] =gopg1(x,a) % input: x, a % output: y y= .....; (2) Create a file sucsub1.m and write a program that calculates the solution using the method of successive substitution. Calculate the values of g(x, a) by making multiple calls to the function gopg1(x, a). Take xo = 1.3 as starting value...

  • 1. (30 points) Write a MATLAB code to perform the Secant method of root finding. Write...

    1. (30 points) Write a MATLAB code to perform the Secant method of root finding. Write the code to output the table used in class showing the iteration, root estimate r,, function value at the root estimate f(r,), and the approximate error. Show that the code works by using it to re-solve Homework Assignment II Problem 2c. Which asked you to find the positive root of f(r) r,1.0 and 6 10-6, have the code iterate until the approximate error is...

  • THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...

    THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such...

  • A use Euler's method with each of the following step sizes to estimate the value of y 0.4 where y...

    a use Euler's method with each of the following step sizes to estimate the value of y 0.4 where y is the solution of the initial value problem y -y, y 0 3 カー0.4 0.4) (i) y10.4) (in) h= 0.1 b we know that the exact solution of the initial value problem n part a s yー3e ra , as accurately as you can the graph of y e r 4 together with the Euler approximations using the step sizes...

  • Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you...

    Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you 5. In this problem we will investigate using the Secant Method to approximate a root of a function f(r). The Secant Method is an iterative approach that begins with initial guesses , and r2. Then, for n > 3, the Secant Method generates approximations of a root of f(z) as In-1-In-2 n=En-1-f (x,-1) f(Fn-1)-f(-2) any iteration, the absolute error in the approximation can be...

  • 3. Consider the function f(x) = -0.1.24 – 0.15x3 – 0.522 – 0.25x + 1.2. (a)...

    3. Consider the function f(x) = -0.1.24 – 0.15x3 – 0.522 – 0.25x + 1.2. (a) Obtain the analytical expression (i.e. True or Exact Solution) for the first derivative, Eval- uate its value at 1 =0.5. Box your answer and label it as fexact- (b) Now assume the function is discretized on a grid with uniform spacing of h. Evaluate your finite difference approximation at x = 0.5 using central differencing with step sizes starting at 1 and re- duced...

  • 4. Given a function f(x), use Taylor approximations to derive a second order one-sided ap- proximation to f'(ro...

    4. Given a function f(x), use Taylor approximations to derive a second order one-sided ap- proximation to f'(ro) is given by f(zo + h) + cf (zo + 21) + 0(h2). f' (zo) = af(xo) + What is the precise form of the error term? Using the formula approximate f' (1) where r) = e* for h 1/(2p) for p = 1 : 15, Form a table with columns giving h, the approximation, absolute error and absolute error divided by...

  • Let f be the function defined by f(x) = 12 exp(x2 – 3x). The function exp(u)...

    Let f be the function defined by f(x) = 12 exp(x2 – 3x). The function exp(u) is another name for e". a) Find L(x) the linear approximation to f at 3. L(x) = help (formulas) b) Use the Linear Approximation for f(x) = 12 exp(x2 – 3x) at 3 to estimate f(3.08). f(3 + 0.08) help (decimals). c) Find the error in the linear approximation to the value of f(3 + 0.08) that we found in part b). The error...

  • (a) Write the following function in Matlab [eval, evec] -power method (A, x, tol) The inputs...

    (a) Write the following function in Matlab [eval, evec] -power method (A, x, tol) The inputs are a matrix A, an initial starting vector r, and tolerance tol. The return value is an approximation to the largest eigenvalue (eval) of A, and the corresponding normalized eigenvector (evec) Your power method implementation should halt (i.e., converge) when this cri- teria is met: where (k) is the current approximate (normalized) eigenvector after k itera- tions. (Note that the "sign" of r() and...

  • Please explain the solution and write clearly for nu, ber 25. Thanks. 25. Approximate the following functions f(x) as a linear combination of the first four Legendre polynomials over the interval [-...

    Please explain the solution and write clearly for nu, ber 25. Thanks. 25. Approximate the following functions f(x) as a linear combination of the first four Legendre polynomials over the interval [-1,1]: Lo(x) = 1, Li(x) = x, L2(x) = x2-1. L3(x) = x3-3x/5. (a) f(x) = X4 (b) f(x) = k (c) f(x) =-1: x < 0, = 1: x 0 Example 8. Approximating e by Legendre Polynomials Let us use the first four Legendre polynomials Lo(x) 1, Li(x)...

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