Calculate the derivative of a segment function

5 visualizaciones (últimos 30 días)
Xuejian Niu
Xuejian Niu el 2 de Feb. de 2022
Comentada: VBBV el 14 de Abr. de 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

Respuestas (1)

VBBV
VBBV el 2 de Feb. de 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 comentarios
Xuejian Niu
Xuejian Niu el 2 de Feb. de 2022
ty so much, smart way~
VBBV
VBBV el 14 de Abr. de 2022
If it solved your problem, pls accept the answer:) thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Linear Algebra en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by