Calculate the derivative of a segment function

6 ビュー (過去 30 日間)
Xuejian Niu
Xuejian Niu 2022 年 2 月 2 日
コメント済み: VBBV 2022 年 4 月 14 日
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 件のコメント
KSSV
KSSV 2022 年 2 月 2 日
DErivative wrt what?

サインインしてコメントする。

回答 (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
  2 件のコメント
Xuejian Niu
Xuejian Niu 2022 年 2 月 2 日
ty so much, smart way~
VBBV
VBBV 2022 年 4 月 14 日
If it solved your problem, pls accept the answer:) thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by