How do I integrate a piecewise function with an upper bound variable

14 views (last 30 days)
As shown in the code, the Angle function alpha is a piecewise function with respect to r (the others are known sign values), and it can be performed as an indeterminate integral or a definite integral of a definite value, but it cannot be calculated when the upper limit of the integral is the variable r. The error message is that the continuity of the function in the integral interval cannot be determined.
...
syms r alpha(r)
alpha(r) = piecewise((r >= part_p(1, 1)) & (r <= part_p(2, 1)), alpha_part(1));
for i = 2:11
alpha(r) = piecewise((r > part_p(2*i-2, 1)) & (r <= part_p(2*i-1, 1)),...
atan(((-1)^(mod(i, 2)) * (r - cir_x(i)) / sqrt(cir_r(i)^2 - (r - cir_x(i))^2))), alpha(r));
alpha(r) = piecewise((r > part_p(2*i-1, 1)) & (r <= part_p(2*i, 1)),...
alpha_part(i), alpha(r));
end
syms arcLength(r)
arcLength(r) = int(sqrt(tan(alpha)^2 + 1), [part_p(1, 1), r]);
  5 Comments
Sam Chak
Sam Chak on 16 Dec 2024
It is somewhat difficult to interpret the lines from a mathematician's perspective. Therefore, I attempted to separate them. The sub-functions of part_p() and alpha_part() are unknown. Are they mathematically defined, or do they refer to a table (cell) from which you extract fixed values?
syms alpha(r)
condition_1 = r >= part_p(1, 1); % condition 1
condition_2 = r <= part_p(2, 1); % condition 2
outcome = alpha_part(1); % outcome
%% Piecewise function
alpha(r) = piecewise(condition_1 & condition_2, outcome);
沐欣
沐欣 on 17 Dec 2024
@Paul@Sam ChakGiven the complete code of main part, alpha() describes the r-direction angle of a wavy line (consisting of the arcs and the tangents between the arcs). part_p(22*2sym) is the calculated coordinates of the segment points, and alpha_part(1*11sym) is the angles of each tangent line.
% 波间距列表
b = arrayfun(@(i) cal_b(i, 0, 1, 0), 1:11);
% 圆弧半径列表
cir_r = repmat(sym(1.432), 1, 11);
% 波高
height = sym(8.349);
% 圆心坐标列表
cir_x = sym(zeros(1, 12));
cir_y = sym(zeros(1, 12));
cir_x(1) = sym(76.886);
for i = 1:11 % 10个圆弧+末尾点
cir_x(i+1) = cir_x(i) + b(i);
if i == 11
cir_y(i+1) = -height;
elseif mod(i, 2) == 1
cir_y(i+1) = cir_r(i) - height;
else
cir_y(i+1) = -cir_r(i);
end
end
% 定义分段切线夹角和分段函数边界
alpha_part = sym(zeros(1, 11)); % 分段切线夹角
part_p = sym(zeros(22, 2)); % 分段点
part_p(1, :) = [cir_x(1), cir_y(1)];
% 单点与圆切点,点在连心线之下(初始点与第一个波谷)
[tang1_cir_x, tang1_cir_y, tang2_cir_x, tang2_cir_y, angle1, angle2] = ...
cal_contant_point(cir_x(2), cir_y(2), cir_r(2), cir_x(1), cir_y(1));
alpha_part(1) = angle1;
part_p(2, :) = [tang1_cir_x, tang1_cir_y];
% 计算两圆弧之间的切线
for i = 2:10 % 10个圆弧间9个波间距
if mod(i, 2) == 0
[alpha1, alpha2, tang1_cir1_x, tang1_cir1_y, tang1_cir2_x, tang1_cir2_y, ...
tang2_cir1_x, tang2_cir1_y, tang2_cir2_x, tang2_cir2_y] = ...
cal_tangents(cir_x(i), cir_y(i), cir_r(i), cir_x(i+1), cir_y(i+1), cir_r(i+1));
alpha_part(i) = alpha1;
part_p(2*i-1, :) = [tang1_cir1_x, tang1_cir1_y];
part_p(2*i, :) = [tang1_cir2_x, tang1_cir2_y];
else
[alpha1, alpha2, tang1_cir1_x, tang1_cir1_y, tang1_cir2_x, tang1_cir2_y, ...
tang2_cir1_x, tang2_cir1_y, tang2_cir2_x, tang2_cir2_y] = ...
cal_tangents(cir_x(i), cir_y(i), cir_r(i), cir_x(i+1), cir_y(i+1), cir_r(i+1));
alpha_part(i) = alpha2;
part_p(2*i-1, :) = [tang2_cir1_x, tang2_cir1_y];
part_p(2*i, :) = [tang2_cir2_x, tang2_cir2_y];
end
end
% 单点与圆切点,点在连心线之上(最外的点与最后一个波峰)
[tang1_cir_x, tang1_cir_y, tang2_cir_x, tang2_cir_y, angle1, angle2] = ...
cal_contant_point(cir_x(11), cir_y(11), cir_r(11), cir_x(12), cir_y(12));
alpha_part(11) = angle2;
part_p(21, :) = [tang2_cir_x, tang2_cir_y];
part_p(22, :) = [cir_x(12), cir_y(12)];
% 建立转角函数
syms r alpha(r)
% alpha(r) = piecewise((r >= part_p(1, 1)) & (r <= part_p(2, 1)), alpha_part(1), ...
% (r > part_p(2, 1)) & (r <= part_p(3, 1)), atan(-1 * (r - cir_x(2)) / sqrt(cir_r(2)^2 - (r - cir_x(2))^2)),...
% (r >= part_p(3, 1)) & (r <= part_p(4, 1)), alpha_part(2),...
% (r > part_p(4, 1)) & (r <= part_p(5, 1)), atan((r - cir_x(3)) / sqrt(cir_r(3)^2 - (r - cir_x(3))^2)),...
% (r >= part_p(6, 1)) & (r <= part_p(7, 1)), alpha_part(3),...);
alpha(r) = piecewise((r >= part_p(1, 1)) & (r <= part_p(2, 1)), alpha_part(1));
for i = 2:11
alpha(r) = piecewise((r > part_p(2*i-2, 1)) & (r <= part_p(2*i-1, 1)),...
atan(((-1)^(mod(i, 2)) * (r - cir_x(i)) / sqrt(cir_r(i)^2 - (r - cir_x(i))^2))), alpha(r));
alpha(r) = piecewise((r > part_p(2*i-1, 1)) & (r <= part_p(2*i, 1)),...
alpha_part(i), alpha(r));
end
alpha = simplify(alpha);
disp('转角函数已建立')
% fplot(alpha, [78, 126])
% 计算弧长
arcLength = simplify(int(sqrt(tan(alpha)^2 + 1), r, [part_p(1, 1), r]));

Sign in to comment.

Answers (0)

Tags

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!