Answered step by step
Verified Expert Solution
Link Copied!

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 image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

=+ a. How does this change affect the incentives for working?

Answered: 1 week ago

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago