# How to estimate data plots as an exponential with a horizontal Asymptote? y=Ax^B+C where B<1

10 visualizzazioni (ultimi 30 giorni)
Dominic Bruce il 11 Apr 2023
Risposto: Sam Chak il 11 Apr 2023
I am trying to find what my data will equal as x tends towards infinity, This should be possible by estimating the plots as y=Ax^B+C where B<1. I have 4 data sets which should all theoretically have the same value for C but diferent A and B values.
Below are my code and the errors;
Code:
syms A B C; % equation coefficient symbols to be solved
x=[0.5 1 2 3];
y=[292.4 264.8 324 305; 182.2 175.6 202.4 199.6; 108.8 112.6 113.2 124.3; 79.8 82.7 94.2 97.6];
for i=1:4
[solA, solB, solC] = solve(A*x(1)^B + C == y(1,i), A*x(2)^B + C == y(2,i), A*x(3)^B + C == y(3,i), A*x(4)^B + C == y(4,i));
% convert the symbolic answers into numerical form
A_vals(i) = double(solA);
B_vals(i) = double(solB);
C_vals(i) = double(solC);
end
Errors
Unable to perform assignment because the left and right sides have a
different number of elements.
Error in Project (line 8)
A_vals(i) = double(solA);
Thank You
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Sam Chak il 11 Apr 2023
Are you looking for something like this?
x = [0.5 1 2 3];
y = [292.4 264.8 324 305; 182.2 175.6 202.4 199.6; 108.8 112.6 113.2 124.3; 79.8 82.7 94.2 97.6];
fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[300, 0, 50],...
'Upper',[500, Inf, 100],...
'StartPoint',[400 1 75]);
ft = fittype('a*exp(-x/b) + c', 'options', fo);
for j = 1:4
[curve, gof] = fit(x', y(:,j), ft);
A(j) = curve.a;
B(j) = curve.b;
C(j) = curve.c;
plot(x, y(:,j), 'o'), hold on
end
a = mean(A);
b = mean(B);
c = mean(C) % horizontal asymptote
c = 82.8209
x = linspace(0.5, 3, 2501);
y = a*exp(-x/b) + c;
plot(x, y, '--', 'linewidth', 1.5, 'Color', '#528AF9'), hold off, grid on
xlabel('x'), ylabel('y') ##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Calculus in Help Center e File Exchange

R2023a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!