Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ME/AE 342 - Numerical Methods in Engineering with Applications Homework 4 1. Write a Matlab function that accepts a vector of values and returns a

image text in transcribedimage text in transcribed

ME/AE 342 - Numerical Methods in Engineering with Applications Homework 4 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 fiti - fi-1 da 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 cos(2712) on the domain re [0,1]. For the points use a regularly spaced array of node locations with a node at both r = 0 and = 1. This array can be generated easily in Matlab using the linspace command such as points = linspace(0, 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 = cos(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() (not cos(272)) at the points x = 0 and r = 1/2 as a function of N. Use the same point distribution as in the previous problem i.e. points = linspace(0, 1, 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

More Books

Students also viewed these Databases questions