how to differentiate and plot of this function
3 ビュー (過去 30 日間)
古いコメントを表示
k1= @(x) sqrt(1-x^2);
k2=@(x) sqrt(2-x^2);
k3=@(x) sqrt(3-x^2);
k4=@(x) sqrt(4-x^2);
r1=@(x) (k1-k2)/(k1+k2);
r2=@(x) (k3-k4)/(k3+k4);
r3= @(x) (k2-k3)/(k2+k3);
y=@(x,d2,d3) -2*atan(1i*(1-r1)/(1+r1))*exp((1-r2*k1*d2)/(1+r2*km*d2))--2*atan(1i*(1-r3)/(1+r3))*exp((1-k2*d3)/(1+r4*k2*d3));
how to calculate dy/dx dy/dd2 and dy/dd3
plot d2 vs dy/dd2/dy/dd3
variation of d2 from 1 to 100;
y is multivariable depending upon d2,d3 x
1 件のコメント
回答 (1 件)
Hiro Yoshino
2022 年 1 月 25 日
編集済み: Hiro Yoshino
2022 年 1 月 25 日
Why don't you use symbolic math expressions as follows?
Please run the script below:
syms k1(x) k2(x) k3(x) k4(x) r1(x) r2(x) r3(x) y(x,d2,d3)
k1 = sqrt(1-x^2)
k2 = sqrt(2-x^2)
k3 = sqrt(3-x^2)
k4 = sqrt(4-x^2)
r1 = (k1-k1)/(k1+k2)
r2 = (k3-k4)/(k3+k4)
r3 = (k2-k3)/(k2+k3)
Note that the first term (atan) does not work due to its singularity and you've got some typos in the expression and I corrected as follows:
y = -2*atan((1-r1)/(1+r1)) *exp((1-r2*k1*d2)/(1+r2*k1*d2))-2*atan(1i*(1-r3)/(1+r3))*exp((1-k2*d3)/(1+r3*k2*d3))
dydx = diff(y,x)
dydd3 = diff(y,d2)
dydd4 = diff(y,d3)
2 件のコメント
Hiro Yoshino
2022 年 1 月 25 日
I don't think what you want to do is solve anything. I suppose you want to derive the partial derivatives.
Iif you want to get the analytic forms of the derivatives, use Symbolic Math otherwise numerical derivative would be a good fit.
The easiest way to use numerical derivative is use "approximation" such as numerical derivatives - you can chop the variables into small intervals and perform the calculations as shown in the document.
参考
カテゴリ
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!