How do I integrate a piecewise function with an upper bound variable
Show older comments
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
Please provide the full code that doesn't result in any errors
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]);
Walter Roberson
on 15 Dec 2024
I would suggest a different method for constructing the piecewise polynomial:
Construct a cell array C that is 2 x 11. Make the first row the conditions (r > part_p(2*i-2, 1)) & (r <= part_p(2*i-1, 1) . Make tthe second row the value corresponding to the conditions, mostly atan(((-1)^(mod(i, 2)) * (r - cir_x(i)) / sqrt(cir_r(i)^2 - (r - cir_x(i))^2)))
Now
alpha = piecewise(C{:})
You can reduce the work a lot by using
num2cell(r >= part_p(1:2:end) & r <= part_p(2:2:end))
and
i = 2:11;
num2cell(atan(((-1).^(mod(i, 2)) .* (r - cir_x(i)) ./ sqrt(cir_r(i).^2 - (r - cir_x(i)).^2))))
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
Answers (0)
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!