Question

Recall that the command diff(f(x),x) symbolically finds the derivative of the function f. Recall also that...

Recall that the command diff(f(x),x) symbolically finds the derivative of the function f. Recall also that the derivative is itself a function which can also be differentiated, giving us the second derivative of f, and so on. MATLAB will easily compute higher order derivatives using the command

diff(f(x),x,n)

Where n represents which derivative you want.

Later, it will be very useful to find patterns in higher order derivatives. Ordinarily, this is most easily done by NOT simplifying the resulting expression, but in this problem, we will illustrate the idea on a function in which this is not a problem: Given the function f( x ) = 1 / x , use a loop to create an 8-element vector df1 whose n th element represents the n th derivative of f evaluated at x = 1. Show the loop in your code (no semicolon) and see if you can generalize the pattern to give a formula for the n th derivative of f at x = 1. If you need help with the syntax for a loop, refer to MATLAB's online documentation: http://www.mathworks.com/help/matlab/ref/for.html

% Define variables

syms ;

f=@(x) ;

% Loop to create vector df1

for i= ;

deriv=diff( ); % Find the general ith derivative of f

df1(i)=subs( ); % Substitute x=1

end; % DO NOT CHANGE CODE ON THIS LINE

df1 % Display the vector df1

.

Homework Answers

Answer #1

The Matlab script is posted below. Run the script to display the result in Command Window. The screen shot of the script and result in also posted at the end.

derivVector.m

clear, clc;

syms x
f = @(x) 1/x;

df1 = zeros(1, 8);

for i = 1 : 8
    deriv = diff(f, x, i);
    df1(i) = subs(deriv, 1);
end

df1
% disp(df1)

Know the answer?
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
Similar Questions