Derivating a variable with respect to other vars
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have the following variable:
Which I want to derivate with respect to UMin and with respect to a1 , and then to do the following:
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 comentarios
Respuestas (1)
Riccardo Scorretti
el 8 de Abr. de 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)
Ver también
Categorías
Más información sobre Number Theory en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!