Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code in MATLAB a function which the Test Cases below are to verify correct code. Write a function with the header [df] = my Partial
Code in MATLAB a function which the Test Cases below are to verify correct code.
Write a function with the header [df] = my Partial Deriv (f, x, ind, eps) which calculates the partial derivative using the central difference method of function f with respect to x (ind). The central difference approximation of a function evaluated at x is: f' = f(x + h) - f(x - h)/2 element and eps is used to permute x (ind) such that when ind = 1: h = [element 0 0], when ind = 2: h = [0 element 0] and when ind = 3: h = [0 0 element] f_1(x, y, z) = 9x^2 + 36y^2 + 4z^2 - 36 f_2(x, y, z) = x^2 + 2y^2 - 20z f_3(x, y, z) = x^2 - y^2 + z^2 >> f1 = @ (x) 98 x(1).^2 + 36* x(2)^2 + 4*x(2)^2 + 48x(3).^2 - 36; >> f2 = @ (x) x(1).^2 - 2*x(2).^2 - 20*x(3); >> f3 = @ (x) x(1).^2 - x(2) - x(2).^2 + x(3).^2; >> x = [-1; 0; -1]; >> s = my Partial Deriv (f1, x, 1, le-7) s = -17.9999999971869 >> s = my Partial Deriv (f2, x, 3, le-7) s = -20.0000000027956 >> s = my Partial Deriv (f3, x, 1, le-7) s = -2.00000000116773 >> s = my Partial Deriv (f3, x, 2, le-7) s = 0 >> my F = @ (x) 4 *sin (x) + exp (x); >> my Partial Deriv (myF, x, 1, le-6) >> my Partial Deriv (myF, pi/17, 1, le-6) ans = 5.1349 You can implement this function with three lines of code. (Or fewer.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started