To create a code that differentiate any function
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (2개)
John D'Errico
2020년 3월 27일
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
Walter Roberson
2020년 3월 27일
편집: James Tursa
2020년 3월 27일
fun = str2sym(input('fun= ', 's'));
var = str2sym(input('which variable= ', 's'));
y = diff(fun, var)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!