Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write a Matlab function that accepts a vector of values and returns a vector of derivatives at those points. You can assume that the

image text in transcribedimage text in transcribed

1. Write a Matlab function that accepts a vector of values and returns a vector of derivatives at those points. You can assume that the values are given on an equally spaced array with spacing h. Use the two point central difference formula df fit1- fi-1 dr 2h for all points except the two endpoints. For the endpoints use a one-sided derivative that uses two points. The function should have the form function [derivative values]- derivative(h,values) The argument h is the spacing between the points and the vector values con- tains the function values. The returned vector derivative values should be a vector of the same length as values 2. Demonstrate that your function works by calculating the derivative of sin(2Tr) on the domain r E [0,1. For the points use a regularly spaced array of node locations with a node at both 1-0 and 1-1. This array can be generated easily in Matlab using the linspace command such as points - linspace(O, 1, N) where N is the number of points you would like to use. For this assignment, you will do this 4 times with N- 3,5, 9, 17 so you can see how the approximation changes as the number of points increases (h decreasing by a factor of 2). Once the points are calculated, the function values can be calculated as values sin(2*pi*points,) To see what the derivative looks like use your function to calculate the deriva- tive values (for N 3,5,9, 17) then plot all the results on the same plot using plot(points,derivative_values); hold on (repeated for each value of N) 3. Use your code to calculate the absolute errors in the derivative of sin(x) at the points | = 0 and 1-1/2 as a function of N. Make a loglog plot of the errors versus N for N- 3,5,9,17

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions