Question

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

.

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)

1:
A) Given the following vectorized code:
>>x=[1:10];
>>f=x.^2+2;
Rewrite this code using a for loop that defines each element of f
one at a time. Make sure to preallocate memory to f before filling
each spot.
B)
See the following code. Rewrite the code in one line using the
find function and a For loop. then write it again using a while
loop
x=[-1 3 7 2 4 0];
v=[];
for i=1:length(x)
if x(i)<=2
v=[v, x(i)];
end
end
please...

Curve-Fit Function USING MATLAB
Using the top-down design approach, develop a MATLAB function
A8P2RAlastname.m that reads data from a file and performs
regression analysis using polyfit and polyval. The function shall
have the following features:
The input arguments shall include the file name (string), a
vector of integers for the degrees of polynomial fits to be
determined, and an optional plot type specifier (‘m’ for multiple
plots, ‘s’ for a single plot - default).
The data files will be text...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 23 minutes ago

asked 37 minutes ago

asked 45 minutes ago

asked 45 minutes ago

asked 50 minutes ago

asked 1 hour ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago

asked 3 hours ago

asked 3 hours ago

asked 3 hours ago