![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/375281/image.png)
how to plot the drivative ?
7 views (last 30 days)
Show older comments
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');
y= diff(Wi);
s=diff(s);
c=diff(omega);
plot(s,y,'r');
how can I plot this ? because it doesn't give me to plot y over s
3 Comments
VBBV
on 9 Oct 2020
Edited: VBBV
on 9 Oct 2020
you are using hold off in your program. So its plotting only the last figure. Use the legend function in the last line preferably to match the variables. You are taking the diff of the vector s . The max value in s is 0.05
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,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,9.92*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 on
xlabel('spin'),ylabel('angular velocity'),legend('r-prograde Isco angular velocity','y-retrograde ISCO angular velocity','b-LR angular velocity','g-given angular velocity');
y= diff(Wi);
s=diff(s);
c=diff(omega);
plot(s,y,'r');
Answers (1)
Karan Singh
on 2 Feb 2025 at 9:08
Edited: Karan Singh
on 2 Feb 2025 at 9:08
I think you are incorrectly reassigns s to diff(s), which causes issues because s is no longer the original x-axis values.The derivative is not computed correctly because y is just the difference in Wi, not the actual derivative (dWi/ds). Also the derivative plot was attempted in the same figure as the original data.
Here is my attempt for you to check.
s = [0,5e-2,1e-1,1.5e-1,2e-1,2.5e-1,3e-1,3.5e-1,4e-1,4.5e-1,5e-1,5.5e-1,6e-1,6.5e-1,7e-1,7.5e-1,8e-1,8.5e-1,9e-1,9.5e-1,9.9e-1,9.99e-1,1,1,1,1,1];
omega = [3.74e-1,3.8e-1,3.87e-1,3.94e-1,4.02e-1,4.11e-1,4.2e-1,4.29e-1,4.4e-1,4.51e-1,4.64e-1,4.78e-1,4.94e-1,5.12e-1,5.33e-1,5.57e-1,5.86e-1,6.23e-1,6.72e-1,7.46e-1,8.71e-1,9.56e-1,9.68e-1,9.72e-1,9.75e-1,9.8e-1,9.86e-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;
figure;
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');
% Compute the derivative of Wi with respect to s
dWi = diff(Wi); % Differences in Wi
ds = diff(s); % Differences in s
derivative_Wi = dWi ./ ds; % Derivative of Wi
figure;
plot(s(1:end-1), derivative_Wi, 'r');
xlabel('spin');
ylabel('d(Wi)/ds');
title('Derivative of Wi with respect to s');
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!