How to find the derivative of y with respect to x (hard code derivative equation into the m-file, do not use symbolic toolbox)

10 views (last 30 days)
My teacher has given me a task which is to plot the derivative of cost against x. Before I can plot the graph, I would need some way to find the gradient at each point in my graph. I am not allowed to use symbolic function and was told to hard code the derivative equation. Does anyone have any idea how to tackle this problem or perhaps provide me with a sample code? Thanks.
This is my code for plotting the graph of cost against x.
I have no idea how to start to find the gradient for all my x points on the curve.

Accepted Answer

Geoff Hayes
Geoff Hayes on 13 May 2020
Jacky - if your cost equation is (with x the variable and D and L are constants)
f(x) = (2.5*10^6)*sqrt(D^2 + x^2) + (2.0*10^6)*(L - x);
then can't you just apply the chain rule to determine the derivative of f(x)?

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!