Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 43Step 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