Question: MATLAB how can I write the code for step 4,5,6 ... the code for forward,backward,central in MATLAB 6%1. Define this function 7 %f(x)--x^2 + 2x-1

MATLAB MATLAB how can I write the code for step 4,5,6 ... the

how can I write the code for step 4,5,6 ... the code for forward,backward,central in MATLAB

6%1. Define this function 7 %f(x)--x^2 + 2x-1 8 syms f(x, y) 9 f(x)--x"2+2*x-1 10 as a symbolic function: 12 %2. Define the derivative of f wrt to x and save to variable 13 %df; 14 15 df- diff(f,x) 16 17 18 %3. Save the derivative of df evaluated at x = 1, to the variable derivAnalytic 19 df2 df (1) 20 21 derivAnalytic = df2 23 24 25 26 %%Numerical Differentiation using Differencing use the data below (xd, fd) 27 %%Course Grid 28 xd --5:2:5; 29 fd --xd."2 + 2*xd - 1; 30 ind find(xd--1); 32%4. Approximate the derivative at x = 1 (which is at ind-4), by using a 33%forward difference approximation, to the variable derivForwa rd 34 35 36 37%5. Approximate the derivative at x = 1 (which is at ind=4), by using a 38%backward difference approximation, to the variable derivBackward 39 48 4186, Approximate the derivative at x 1 (which is at ind-4), by using a 42 %central difference approximation, to the variable derivcentral 43 6%1. Define this function 7 %f(x)--x^2 + 2x-1 8 syms f(x, y) 9 f(x)--x"2+2*x-1 10 as a symbolic function: 12 %2. Define the derivative of f wrt to x and save to variable 13 %df; 14 15 df- diff(f,x) 16 17 18 %3. Save the derivative of df evaluated at x = 1, to the variable derivAnalytic 19 df2 df (1) 20 21 derivAnalytic = df2 23 24 25 26 %%Numerical Differentiation using Differencing use the data below (xd, fd) 27 %%Course Grid 28 xd --5:2:5; 29 fd --xd."2 + 2*xd - 1; 30 ind find(xd--1); 32%4. Approximate the derivative at x = 1 (which is at ind-4), by using a 33%forward difference approximation, to the variable derivForwa rd 34 35 36 37%5. Approximate the derivative at x = 1 (which is at ind=4), by using a 38%backward difference approximation, to the variable derivBackward 39 48 4186, Approximate the derivative at x 1 (which is at ind-4), by using a 42 %central difference approximation, to the variable derivcentral 43

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!