Question

(10 pts) Write a function to call python modules (either re-write or re-use the program you developed before) to calculate th

0 0
Add a comment Improve this question Transcribed image text
Answer #1
https://trinket.io/python3/ea5cc4c872

import numpy as np
import matplotlib.pyplot as plt
def f(x):
return np.log(1+x);
h=np.logspace(-1,-15,15);
x=1;
Df1=(f(x+h)-f(x))/h;
Df2=(f(x+h)-f(x-h))/(2*h);
Df3=(f(x)-f(x-h))/h;
plt.loglog(h,abs(Df1-1.0/(1.0+x)));
plt.loglog(h,abs(Df2-1.0/(1.0+x)));
plt.loglog(h,abs(Df3-1.0/(1.0+x)));
plt.legend(['Forward','Central','Extrapolated']);
plt.show();
print(Df1)
print(Df2)
print(Df3)

Add a comment
Know the answer?
Add Answer to:
(10 pts) Write a function to call python modules (either re-write or re-use the program you...
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 me a Matlab script that will compute the total errors of the approximation due...

    please show me a Matlab script that will compute the total errors of the approximation due to the given function, also include the panel plot as well, thank you. 1) This problem studies the errors due to the approximation of the first derivative of a given function f(x) using the forward and centered difference methods. For this problem, we consider f(x)=sin(x). a) First, we will investigate the effect of the step size h on the first derivative approximation. Set h=10',...

  • Estimate the second derivative of the following function using stencils for the FORWARD and CENTRAL derivatives for an order of accuracy of O(h2) for each. Use a step size of h -1. fo)x-2x2...

    Estimate the second derivative of the following function using stencils for the FORWARD and CENTRAL derivatives for an order of accuracy of O(h2) for each. Use a step size of h -1. fo)x-2x2 +6 Second derivative, Forward Difference Approximation, o(h2)- Second derivative, Central Difference Approximation, O(h2) Which of the two methods is closer to the true value? (Forward/Central 12.5 points Differential Equation Estimate the second derivative of the following function using stencils for the FORWARD an derivatives for an order...

  • 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...

  • Design and construct a computer program in Java. The following is a plot of the function...

    Design and construct a computer program in Java. The following is a plot of the function f(x) = sin(x3) + x2 : In order to illustrate the effects of the two major error sources, rounding and truncation, attempt to determine an approximation to the derivative of f(x) at x = 2.0 radians using the difference approximation given below. (The true answer is 4 + 12 cos(8) or about 2.2539995942966376896). Use the formula: f'(x) ≃ (f(x+h) - f(x)) / h with...

  • Use Mat Lab to write a function called forwarddiff.m that takes data sample locations and function...

    Use Mat Lab to write a function called forwarddiff.m that takes data sample locations and function samplings at those locations as inputs and returns an approximation of the derivative at the sample points based on forward finite difference method with order of accuracy O(h^3). The function should display nothing to the screen unless an error or warning occurs. The detailed specification is as follows: The approximation of derivative by forward difference method (for O(h^3) is given as: f' (x_1) =...

  • Problem 3 In this problem you add some random noise to the sine function and then...

    Problem 3 In this problem you add some random noise to the sine function and then calculate the derivative. • First, generate a vector (the same length as x, above) which consists of random numbers in the range (-0.02) to (0.02). Use the MATLAB function rand. rand will return a random number between 0 and 1. For this problem, you actually need random numbers between +/- 0.02. How will you convert the random numbers you obtain from rand to be...

  • 1 st s2, y(1)1 The exact solution is given by yo) - = . 1+Int Write a MATLAB code to approximate ...

    1 st s2, y(1)1 The exact solution is given by yo) - = . 1+Int Write a MATLAB code to approximate the solution of the IVP using Midpoint (RK2) and Modified Euler methods when h [0.5 0.1 0.0s 0.01 0.005 0.001]. A) Find the vector w mid and w mod that approximates the solution of the IVP for different values of h. B) Plot the step-size h versus the relative error of both in the same figure using the LOGLOG...

  • (a) Use the following data to find the velocity and acceleration at t = 10 seconds:

    Numerical methods(a)  Use the following data to find the velocity and acceleration at t = 10 seconds:Time (s):0246810121416Position (m):00.71.83.45.16.37.38.08.4Use second-order correct (i) centered finite-difference, and (ii) backward finite-difference methods. (b)  Use the Taylor expansions for f(x +h), f(x+2h), f(x +3h) and derive the following forward finite-difference formulas for the second derivative. Write down the error term$$ f^{\prime \prime}(x) \approx \frac{-f(x+3 h)+4 f(x+2 h)-5 f(x+h)+2 f(x)}{h^{2}} $$

  • Classes and Methods: A class for estimating the derivative of a function f) at the form: takes wh...

    In Python 3.6 Classes and Methods: A class for estimating the derivative of a function f) at the form: takes where h is a small change in x. The goal of this exercise is to use the formula above to differentinte a mat hematical function f(x) implemented as a Python function f(x) Implement class Diff with two special methods. The--init--() method takes in function object and also an optional argument h. The default value of h is le-4. Implement also...

  • Use matlab please. Exercise 2 Use the functions you coded in Exercise 1 to compute the...

    Use matlab please. Exercise 2 Use the functions you coded in Exercise 1 to compute the numerical approximation of the integral .1 cos e 30 To this end, write a Matlab/Octave function function [en,et , es] test-integration() = that returns the following items: em, et, es: row vectors with components the absolute values of the integration errors llref-Inl n=2.3, . . . . 100 obtained with the midpont (vector em), trapezoidal (vector et) and Simpson (vector es) rules. Here, f...

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