Calculate the derivative of a segment function

2 vues (au cours des 30 derniers jours)
Xuejian Niu
Xuejian Niu le 2 Fév 2022
Commenté : VBBV le 14 Avr 2022
a = 0.6;
b = 0.1;
x = linspace(0,3*a,181);
% Here is my segment function
% How can i calculate its derivative
function [yu] = up(x1,a,b)
yu = zeros(size(x1));
for k = 1 : length(yu)
x = x1(k);
if x > 0 && x <= a;
% x is in the range [0, a]
yu(k) = (b^2 - ((b^2)/(a^2)).*(x-a).^2).^(1/2);
else x > a && x < 3*a;
% x is in the range [a, 3*a]
yu(k) = (((b/(4*a^3)).*x.^(3)) - ((3*b)/(2*a^2)).*(x.^2) + (9*b)/(4*a).*x);
end
end
end

Réponses (1)

VBBV
VBBV le 2 Fév 2022
a = 0.6;
b = 0.1;
x = linspace(0,3*a,181);
Y = up(x,a,b); %
plot(x,Y)
% Here is my segment function
% How can i calculate its derivative
function [yu] = up(x1,a,b)
yu = zeros(size(x1));
for k = 1 : length(yu)
x(k) = x1(k);
if x(k) > 0 && x(k) <= a;
% x is in the range [0, a]
yu(k) = (b^2 - ((b^2)/(a^2)).*(x(k)-a).^2).^(1/2);
else x(k) > a && x(k) < 3*a;
% x is in the range [a, 3*a]
yu(k) = (((b/(4*a^3)).*x(k)^(3)) - ((3*b)/(2*a^2)).*(x(k)^2) + (9*b)/(4*a)*x(k));
end
end
yu = gradient(yu)./gradient(x); % derivative using gradient
end
you can use diff as well to check the derivative property
  2 commentaires
Xuejian Niu
Xuejian Niu le 2 Fév 2022
ty so much, smart way~
VBBV
VBBV le 14 Avr 2022
If it solved your problem, pls accept the answer:) thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by