ans =

Hi @rezheen,
So, I did review @Torsten and @Walter Robertson comments, and highly respect their input. To achieve your desired outcome, I did break down the task into several steps. First, I plotted the entire curve, computed the arc length for the specified range, and then modified the plot to only show the arc length segment. Below is the complete MATLAB code that accomplishes this:
% Clear workspace and command window clear; clc;
% Define symbolic variables syms x y real
% Define the function y = (1/3) * (nthroot(x^2 + 2, 2)^3);
% Define the range for arc length x1 = 0; x2 = 2;
% Calculate the y-values at x1 and x2 y1 = subs(y, x, x1); y2 = subs(y, x, x2);
% Plot the entire curve g = fplot(y, 'LineWidth', 1.5); hold on; grid on;
% Calculate the derivative of the function dy = diff(y);
% Calculate the discriminant for arc length discriminant = sqrt(1 + (dy)^2);
% Compute the exact arc length Length_Exact = int(discriminant, x, x1, x2); fprintf('The arc length is exactly %s\n', Length_Exact);
% Calculate the approximate arc length Length_Approx = double(subs(Length_Exact)); fprintf('The arc length is approximately %.4f\n', Length_Approx);
% Plot the arc length segment as a dotted line f = fplot(y, [x1, x2], 'r', 'LineWidth', 1.5, 'LineStyle', '--'); hold on;
% Plot the endpoints of the arc length plot(x1, y1, '.', 'Color', 'b', 'MarkerSize', 15); plot(x2, y2, '.', 'Color', 'b', 'MarkerSize', 15);
% Remove the original curve for the range of x1 to x2 set(g, 'Visible', 'off');
% Finalize the plot title('Arc Length of the Function'); xlabel('x-axis'); ylabel('y-axis'); legend('Entire Curve', 'Arc Length Segment', 'Endpoints', 'Location', 'Best'); hold off;
Please see attached.
By following the provided code, you can effectively distinguish between the entire curve and the specific arc length segment, while also computing the exact arc length. If you have any further questions or need additional modifications, feel free to ask!
Hope this helps.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!