clc
clear
% Data
t = [0 0.5 1 1.5 2 2.5 3 3.5 4];
v = [100 62 38 21 13 7 4 2 3];
% Fit exponential: v = a*e^(bt)
p = polyfit(t, log(v), 1);
b = p(1);
a = exp(p(2));
% Smooth curve
t_fit = linspace(min(t), max(t), 100);
v_fit = a * exp(b * t_fit);
% Plot
figure;
plot(t, v, 'ro', 'LineWidth',2, 'MarkerSize',8); hold on;
plot(t_fit, v_fit, 'b-', 'LineWidth',2);
title('Capacitor Voltage Decay');
xlabel('Time (s)');
ylabel('Voltage (V)');
legend('Data','Exponential Fit','Location','northeast');
grid on;
% Display equation
fprintf('v(t) = %.4f * e^(%.4f t)\n', a, b);
To embed this project on your website, copy the following code and paste it into your website's HTML: