clc 
clear 

x_a = [25, 30, 35, 40, 45];
y_a = [5, 260, 480, 745, 1100];
x_b = [2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 7, 8, 9, 10];
y_b = [1500, 1220, 1050, 915, 810, 745, 690, 620, 520, 480, 410, 390];
linear_fit = @(p, x) p(1) * x + p(2);
exp_fit = @(p, x) p(1) * exp(p(2) * x);
power_fit = @(p, x) p(1) * x.^p(2);
fit_error = @(fit_func, params, x, y) sum((fit_func(params, x) - y).^2);
params_linear_a = fminsearch(@(p) fit_error(linear_fit, p, x_a, y_a), [1, 1]);
params_exp_a = fminsearch(@(p) fit_error(exp_fit, p, x_a, y_a), [1, 0.01]);
params_power_a = fminsearch(@(p) fit_error(power_fit, p, x_a, y_a), [1, 1]);
params_linear_b = fminsearch(@(p) fit_error(linear_fit, p, x_b, y_b), [1, 1]);
params_exp_b = fminsearch(@(p) fit_error(exp_fit, p, x_b, y_b), [1, -0.01]);
params_power_b = fminsearch(@(p) fit_error(power_fit, p, x_b, y_b), [1, -1]);
x_fit_a = linspace(min(x_a), max(x_a), 100);
x_fit_b = linspace(min(x_b), max(x_b), 100);
y_linear_a = linear_fit(params_linear_a, x_fit_a);
y_exp_a = exp_fit(params_exp_a, x_fit_a);
y_power_a = power_fit(params_power_a, x_fit_a);
y_linear_b = linear_fit(params_linear_b, x_fit_b);
y_exp_b = exp_fit(params_exp_b, x_fit_b);
y_power_b = power_fit(params_power_b, x_fit_b);
figure;
subplot(1, 2, 1);
scatter(x_a, y_a, 'b', 'DisplayName', 'Data A');
hold on;
plot(x_fit_a, y_linear_a, 'r--', 'DisplayName', 'Linear Fit');
plot(x_fit_a, y_exp_a, 'g--', 'DisplayName', 'Exponential Fit');
plot(x_fit_a, y_power_a, 'm-', 'DisplayName', 'Power Fit');
title('Dataset A');
xlabel('X');
ylabel('Y');
legend;
grid on;
subplot(1, 2, 2);
scatter(x_b, y_b, 'b', 'DisplayName', 'Data B');
hold on;
plot(x_fit_b, y_linear_b, 'r--', 'DisplayName', 'Linear Fit');
plot(x_fit_b, y_exp_b, 'g--', 'DisplayName', 'Exponential Fit');
plot(x_fit_b, y_power_b, 'm-', 'DisplayName', 'Power Fit');
title('Dataset B');
xlabel('X');
ylabel('Y');
legend;
grid on;

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: