Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE ANSWER USING MATLAB**** The Code for the answer is Below but is written i

ID: 3805522 • Letter: P

Question

PLEASE ANSWER USING MATLAB****

The Code for the answer is Below but is written in Python.

Need the following in MATLAB (assuming the code is correct)

f = lambda x: 1 + 1/2*tanh(2*x) h = 0.5 x = linspace(-2,2) f_diff = (f(x + h/2) - f(x - h/2))/h f_diff_a = -tanh(2*x)**2 + 1 plot(x,f_diff,'--') plot(x,f_diff_a,'-') 1. Numerical differentiation: Create a user-defined function fix) that returns the value 1 12 tanh (2x), then use a central difference to calculate the derivative of the function in the range -2 sxs 2. Calculate an analytic formula for the derivative and make a graph with your numerical result and the analytic answer on the same plot. It may help to plot the exact answer as lines and the numerical one as dots. (Hint: In Matlab the tanh function is called simply tanh)

Explanation / Answer

Assuming your python code is correct

function val = fx(x)
val = 1+ (1/2) * (tanh(2 *x))
end

x = linspace(-2,2)
h = 0.5
f_diff = (fx(x+h/2) - fx(x-h/2))/2
f_diff_a = -(power(tanh(2*x),2)) + 1
plot(x,f_diff,'--')
plot(x,f_diff_a,'-')

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote