Trying to use exponential curve fitting, need help.

I have data from tension experiments, which should follow an exponential trend. I would like to use exponential curve fitting on the data to see how closely the collected data matches the expected trend. I consulted the MATLAB documentation ( http://www.mathworks.com/examples/curvefitting/mw/curvefit-ex72685292-fit-exponential-models-using-the-fit-function ), but still receive the following error: Undefined function 'fit' for input arguments of type 'double'. Any suggestions?
My script:
% tension calculations
Beta = 0:pi:6*pi;
% beta is in radians
Tdata = [525,650,1050,1400,1950,2550,4200];
% Tdata is in grams
T2 = Tdata./1000;
%converts grams to kgs
g = 9.81; %m/s/s
force_t = T2.*g;
%converts kg to N
fit_line = fit(Beta,force_t,'exp1');
%generates exponential fit line for data
hold on
plot(Beta,force_t,'ro')
hold on
plot(Beta,fit_line,'k-')
xlim([0 8*pi])
ylabel('Force, N')
xlabel('Beta, radians')
title('Force required to move 5N weight vs Beta');

3 Kommentare

Torsten
Torsten am 3 Nov. 2016
Bearbeitet: Torsten am 3 Nov. 2016
You have licenced the "Curve Fitting Toolbox" ?
Check out
https://de.mathworks.com/matlabcentral/answers/93913-how-can-i-see-which-toolboxes-i-have-installed
Best wishes
Torsten.
No, apparently not. Thank you.
Torsten
Torsten am 3 Nov. 2016
Bearbeitet: Torsten am 3 Nov. 2016
Result of fit is
force_t(Beta) approx. 9.81/1000*453.233*exp(0.116372*Beta)
Best wishes
Torsten.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Star Strider
Star Strider am 3 Nov. 2016
It is a Curve Fitting Toolbox function, but you need only core MATLAB functions to do that fit. Add four lines to your code and you have your result:
% tension calculations
Beta = 0:pi:6*pi;
% beta is in radians
Tdata = [525,650,1050,1400,1950,2550,4200];
% Tdata is in grams
T2 = Tdata./1000;
%converts grams to kgs
g = 9.81; %m/s/s
force_t = T2.*g;
%converts kg to N
fit_exp = @(b,x) b(1) .* exp(b(2).*x); % Objective Function
fcn = @(b) sum((fit_exp(b,Beta) - force_t).^2); % Least-Squares cost function
s = fminsearch(fcn, [max(force_t); -1;]) % Estimate Parameters
fit_line = fit_exp(s, Beta); % Calculate Fitted Equation
%generates exponential fit line for data
figure(1)
plot(Beta,force_t,'ro')
hold on
plot(Beta,fit_line,'k-')
hold off
xlim([0 8*pi])
ylabel('Force, N')
xlabel('Beta, radians')
title('Force required to move 5N weight vs Beta');

Produkte

Gefragt:

am 3 Nov. 2016

Bearbeitet:

am 3 Nov. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by