![]() The Symbolic Math Toolbox supports the Formula Manipulation and Simplification of mathematical functions. To get this to work in the discrete case, you make Δx very small. ![]() If you recall, the definition of the derivative is such that: However, we can still work with the code I wrote above, but fp will have to be defined differently. As such, you don't have a choice but to use the discrete approximation of the derivative to get this to work. If, for some reason, you don't have the Symbolic Mathematics Toolbox, then what I suggested won't work. ![]() If the Symbolic Mathematics Toolbox is missing. Running this modification to your code, I get this for the root with the initial guess at x = 1.4 and the amount of iterations it took: > format long g That's what matlabFunction returns, so there isn't a need to create a handle via as inputs into your Newton's Method function anymore. Take note that f and fp are already function handles. %// Define function handles (numerical) to the original and derivative First create the symbolic definition of your function f, then differentiate this symbolic representation using the symbolic version of diff (which you can just call with diff itself), then create a MATLAB function with matlabFunction out of this: %// Define symbolic variable ![]() Instead, make your f and fp as actual function handles. Out-of-the-box diff performs a difference operation between pairs of elements. You are trying to use diff to differentiate a function. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |