clear all; close all; clc; data = csvread('file.csv'); % Extract the first row as x points x = data(1, :); % Initialize the variable B as an empty matrix B_t0 = []; % Loop over rows num_rows = size(data, 1); num_columns = size(data, 2); coeff = []; % Desired polynomial degree polynomial_degree = 20; % Modify the polynomial degree according to your needs % Define the symbolic variable 'x' x_symbolic = sym('x'); % Loop to obtain polynomial coefficients and generate plots for row = 2:num_rows % Extract the current row as values to interpolate (B) B_current = data(row, :); % Use polyfit to obtain polynomial coefficients coefficients = polyfit(x, B_current, polynomial_degree); % Convert coefficients into a symbolic object symbolic_polynomial = poly2sym(coefficients, x_symbolic); % Get the textual representation of the polynomial string_polynomial = char(symbolic_polynomial); % Display the polynomial representation disp(['Polynomial for row ', num2str(row), ': ', string_polynomial]); % Evaluate the polynomial at x points y_values = polyval(coefficients, x); % Plot the polynomial figure; plot(x, B_current, 'o', x, y_values, 'LineWidth', 2); title(['Polynomial for row ', num2str(row), ', degree ', num2str(polynomial_degree)]); xlabel('x'); ylabel('Polynomial'); legend('Original data', 'Interpolating polynomial', 'Location', 'Best'); grid on; end