how to differentiate and plot of this function

2 views (last 30 days)
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 Comment
KSSV
KSSV on 25 Jan 2022
Did you try to run the code and see?
r1=(k1-k2)/(k1+k2);
What is d2 and d3?

Sign in to comment.

Answers (1)

Hiro Yoshino
Hiro Yoshino on 25 Jan 2022
Edited: Hiro Yoshino on 25 Jan 2022
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)
k1 = 
k2 = sqrt(2-x^2)
k2 = 
k3 = sqrt(3-x^2)
k3 = 
k4 = sqrt(4-x^2)
k4 = 
r1 = (k1-k1)/(k1+k2)
r1 = 
0
r2 = (k3-k4)/(k3+k4)
r2 = 
r3 = (k2-k3)/(k2+k3)
r3 = 
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))
y = 
dydx = diff(y,x)
dydx = 
dydd3 = diff(y,d2)
dydd3 = 
dydd4 = diff(y,d3)
dydd4 = 
  2 Comments
shiv gaur
shiv gaur on 25 Jan 2022
is there any method with out syms pl plot the solve equation
Hiro Yoshino
Hiro Yoshino on 25 Jan 2022
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.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!