Derivating a variable with respect to other vars
3 views (last 30 days)
Show older comments
I have the following variable:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/956130/image.png)
Which I want to derivate with respect to UMin and with respect to a1 , and then to do the following:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/957105/image.png)
When all the deltas are defined variables.
What I am lacking is, how to derivate? I only saw the option to use syms, but I don't think I can use it for my purpose.
2 Comments
Answers (1)
Riccardo Scorretti
on 8 Apr 2022
In my opinion, you can do it analytically:
syms Umin a1
tau = sqrt( (2*Umin-Umin^3+Umin^4+2*Umin^2-8) / (2*a1*Umin^3*(Umin^2+4)^1.5) )
d_tau = simplify(diff(tau, a1))
fun_d_tau = matlabFunction(d_tau)
Example:
Umin = 10 ; a1 = 2 ; format long ; fun_d_tau(Umin,a1)
Otherwise, of course you can do it by finite differences, but the result will be necessarily less accurate. Most importantly, in order to achieve a decent accuracy, in practice you must know at least the order of magnitude of a1. Perhaps the simplest way is:
da1 = 1.0E-7; % *** this depends on the order of magnitude of a1 ***
fun_tau = @(Umin,a1) sqrt( (2*Umin-Umin.^3+Umin.^4+2*Umin.^2-8) / (2*a1.*Umin.^3.*(Umin.^2+4).^1.5) );
fun_d_tau = @(Umin,a1) ( fun_tau(Umin,a1+da1) - fun_tau(Umin,a1-da1) ) / (2.0*da1);
Example:
Umin = 10 ; a1 = 2 ; fun_d_tau(Umin,a1)
Notice that once you have created the object fun_d_tau, you don't have to care anymore of the variable da1. For instance, you can modify its value, or even clear it: the function fun_d_tau will continue to work as well:
clear da1
Umin = 10 ; a1 = 2 ; fun_d_tau(Umin,a1)
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!