Calculate the derivative of a segment function

1 次查看(过去 30 天)
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

回答(1 个)

VBBV
VBBV 2022-2-2
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

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by