how to differentiate and plot of this function
1 次查看(过去 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!