Question
MatLab Help!!
Write a function called Difference to calculate the central difference, forward diflerence, and backward diference approximat
0 0
Add a comment Improve this question Transcribed image text
Answer #1

code

solution

8matalb code %Derivative. m function [back Difference, central Difference, forward Difference=Derivati xmin, xmax, xinc) ve (

%output

anon_Function - @(x) x .a 3 back_Difference 19 37 61 91 127 169 central Difference 28 49 76 109 148 193 forward Difference 37

%copyable code

%matalb code

%Derivative.m

function [back_Difference,central_Difference,forward_Difference]=Derivative(anon_Function,xmin,xmax,xinc)

back_Difference=(anon_Function(xmin:xinc:xmax)-anon_Function(xmin-xinc:xinc:xmax-xinc))/xinc;

central_Difference=(anon_Function(xmin+xinc:xinc:xmax+xinc)-anon_Function(xmin-xinc:xinc:xmax-xinc))/(2*xinc);

forward_Difference=(anon_Function(xmin+xinc:xinc:xmax+xinc)-anon_Function(xmin:xinc:xmax))/xinc;

end

%main.m

anon_Function = @(x) x.^3

xmin=3;

xinc=1;

xmax=8;

[back_Difference, central_Difference, forward_Difference] = Derivative(anon_Function, xmin, xmax, xinc)

Add a comment
Know the answer?
Add Answer to:
MatLab Help!! Write a function called Difference to calculate the central difference, forward diflerence, and backward diference approximation to an function within a given range of xmin:xinc:xmax...
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
  • 5. Create a MATLAB script to find the first and second derivative of given function using Forward, Backward, central an...

    5. Create a MATLAB script to find the first and second derivative of given function using Forward, Backward, central and Taylor numerical schemes. Test your code using the following functions: f(x)-xe*+3x2 +2x -1 and find f (3) and f' (3) for with h 0.1, 0.01 and 0.001 b. Approximate y'(1) and y"(1) using the following table f(x) 0.992 0.8 0.9 0.999 1.0 1.001 1.008 Input: (copy and paste the MATLAB or Scilab script in the following box) 5. Create a...

  • Write a function called ZeroCornersSecondRow that sets the corners of a 2D array to zero and...

    Write a function called ZeroCornersSecondRow that sets the corners of a 2D array to zero and also outputs the second row. The input arguments: • inArray: A double precision 2D array of size nxn, where n is at least 3. The output arguments: outArray: A double precision 2D array of size nxn that is a copy of inArray except with the corners set to zero. • secondRow: A double precision 1D array of size n. This is the second row...

  • MATLAB Only MATLAB Only MATLAB Only Indicated in the script below, write a function, called arbpoly3,...

    MATLAB Only MATLAB Only MATLAB Only Indicated in the script below, write a function, called arbpoly3, that accepts two inputs: i) a row vector, called c, containing the coefficients of the polynomial, starting with the coefficient for the lowest degree term, which is the constant term. ii) a row vector, called x, which is the set of real numbers where the polynomial is to be evaluated. The output, y, will be a vector containing the values of the polynomial, evaluated...

  • [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a...

    [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a vector. The cumulative product, pj, of the jth element of the vector x, xj, is defined by pj = (x1)(x2) … (xj) for j = 1:length of the vector x. DO NOT USE CUMPROD For example, when you run your function it should look like this: >> x = [2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,...

  • Given a list of predicted values and a list of their corresponding observed values, complete the...

    Given a list of predicted values and a list of their corresponding observed values, complete the function FilterOutliers that computes the error of the data, removes outliers, and re-computes the error. The input arguments: • predicted: A double precision 10 array of size n containing the predicted values. . observed: A double precision 1D array of size n containing the observed values • threshold: A double precision positive scalar that determines if an observation is an outlier. The output arguments:...

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