필터 지우기
필터 지우기

Derivating a variable with respect to other vars

조회 수: 1 (최근 30일)
Tal Shavit
Tal Shavit 2022년 4월 7일
댓글: Tal Shavit 2022년 4월 8일
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
Torsten
Torsten 2022년 4월 7일
I don't see a3 in your equation.
Tal Shavit
Tal Shavit 2022년 4월 8일
a1, sorry

댓글을 달려면 로그인하십시오.

답변 (1개)

Riccardo Scorretti
Riccardo Scorretti 2022년 4월 8일
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) )
tau = 
d_tau = simplify(diff(tau, a1))
d_tau = 
fun_d_tau = matlabFunction(d_tau)
fun_d_tau = function_handle with value:
@(Umin,a1)sqrt(2.0).*1.0./Umin.^3.*1.0./a1.^2.*1.0./(Umin.^2+4.0).^(3.0./2.0).*1.0./sqrt((1.0./Umin.^3.*1.0./(Umin.^2+4.0).^(3.0./2.0).*(Umin.*2.0+Umin.^2.*2.0-Umin.^3+Umin.^4-8.0))./a1).*(Umin.*2.0+Umin.^2.*2.0-Umin.^3+Umin.^4-8.0).*(-1.0./4.0)
Example:
Umin = 10 ; a1 = 2 ; format long ; fun_d_tau(Umin,a1)
ans =
-0.011649625737107
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)
ans =
-0.011649625743237
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)
ans =
-0.011649625743237

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by