how to differentiate this ? for example- Wi

1 view (last 30 days)
Tomer Segev
Tomer Segev on 8 Oct 2020
Answered: Karan Singh on 6 Jan 2025
s= [0,5*10^-2,1*10^-1,1.5*10^-1,2*10^-1,2.5*10^-1,3*10^-1,3.5*10^-1,4*10^-1,4.5*10^-1,5*10^-1,5.5*10^-1,6*10^-1,6.5*10^-1,7*10^-1,7.5*10^-1,8*10^-1,8.5*10^-1,9*10^-1,9.5*10^-1,9.9*10^-1,9.99*10^-1,1,1,1,1,1];
omega= [3.74*10^-1, 3.8*10^-1,3.87*10^-1,3.94*10^-1,4.02*10^-1,4.11*10^-1,4.2*10^-1,4.29*10^-1,4.4*10^-1,4.51*10^-1,4.64*10^-1,4.78*10^-1,4.94*10^-1,5.12*10^-1,5.33*10^-1,5.57*10^-1,5.86*10^-1,6.23*10^-1,6.72*10^-1,7.46*10^-1,8.71*10^-1,9.56*10^-1,9.68*10^-1,9.72*10^-1,9.75*10^-1,9.8*10^-1,9.86*10^-1];
Z1= 1+((1-(s.^2)).^(1/3)).*(((1+s).^(1/3))+(1-s).^(1/3));
Z2= sqrt(3*(s.^2)+(Z1.^2));
Ri= 3+Z2-sqrt((3-Z1).*(3+Z1+2.*Z2));R= 3+Z2+(sqrt((3-Z1).*(3+Z1+2.*Z2)));
Wi= (s+((Ri).^(3/2))).^-1;
WR= (s+((R).^(3/2))).^-1;
Rlr= 2*(1+cos((2/3)*acos(-s)));
Wlr= (s+((Rlr).^2)).^-1;
plot(s,Wi,'r');
hold on
plot(s,WR,'y'),plot(s,Wlr,'b'),plot(s,omega,'g');
hold off
xlabel('spin'),ylabel('angular velocity'),legend('r-prograde Isco angular velocity','y-retrograde ISCO angular velocity','b-LR angular velocity','g-given angular velocity');
i need the derivative function of W (any of them) they are functions of s, and some r but all the r are functions of s.
and then I want to plot Wi as a function of s

Answers (1)

Karan Singh
Karan Singh on 6 Jan 2025
Hi Tomer,
Symbolic toolbox should fit well
% Symbolic Variables
syms s
% Define Z1, Z2, Ri, R, Wi (symbolically as functions of s)
Z1 = 1 + ((1 - s^2)^(1/3)) * (((1 + s)^(1/3)) + (1 - s)^(1/3));
Z2 = sqrt(3*s^2 + Z1^2);
Ri = 3 + Z2 - sqrt((3 - Z1) * (3 + Z1 + 2*Z2));
Wi = (s + Ri^(3/2))^(-1);
% Differentiate Wi with respect to s
dWi_ds = diff(Wi, s);
% Convert the symbolic derivative to a MATLAB function
Wi_func = matlabFunction(Wi, 'Vars', s);
dWi_ds_func = matlabFunction(dWi_ds, 'Vars', s);
% Generate s values (numerical range)
s_vals = linspace(0, 1, 100);
% Evaluate Wi and its derivative numerically
Wi_vals = Wi_func(s_vals);
dWi_ds_vals = dWi_ds_func(s_vals);
% Plot Wi(s) and its derivative
figure;
subplot(2, 1, 1);
plot(s_vals, Wi_vals, 'r', 'LineWidth', 1.5);
xlabel('s');
ylabel('Wi(s)');
title('Wi(s) vs s');
grid on;
subplot(2, 1, 2);
plot(s_vals, dWi_ds_vals, 'b', 'LineWidth', 1.5);
xlabel('s');
ylabel('dWi/ds');
title('Derivative of Wi(s) vs s');
grid on;

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!