To create a code that differentiate any function
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone!
I want to create a code that differentiate any function. The procedure should be like this: An input function should be entered with respect to "x", "z" or whatever users want and that function should be differentiated with respect to this input.
How I can do this?
Example:
fun= input('fun= '); % let be fun= exp(10*x)*sin(x*y) or fun= ((8*(x^3))*(10*(t^2)))/((3*x*z)+6*x*y)
y= diff(fun,x)
0 Kommentare
Antworten (2)
John D'Errico
am 27 Mär. 2020
Well, you write a complete version of a set of symbolic tools, that can parse any function provided, and know the rules for differentiation. You will need to put all possible functions in, and know how to differentiate them, for example sin(x), etc. The chain rule will be necessary. Of course, you will need to implement computer algebra too, so adds, subtracts, multiplies, divides, powers.
Are you sure you are up to it? For example, I did much of what you want to do, but only for a very simple class of functions - symbolic polynomials. It is doable. You can look at what I did in the sympoly toolbox, since it is available for free download from the file exchange.
The answer will be to be careful, in that you need to limit what you implement. Don't try to write a complete set of tools that can handle ANYTHING. It will fail if you try to be too exhaustive. So start small, and accept that you could add capability with time.
0 Kommentare
Walter Roberson
am 27 Mär. 2020
Bearbeitet: James Tursa
am 27 Mär. 2020
fun = str2sym(input('fun= ', 's'));
var = str2sym(input('which variable= ', 's'));
y = diff(fun, var)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!