Trying to use exponential curve fitting, need help.

4 visualizzazioni (ultimi 30 giorni)
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 Commenti
Torsten
Torsten il 3 Nov 2016
Modificato: Torsten il 3 Nov 2016
Result of fit is
force_t(Beta) approx. 9.81/1000*453.233*exp(0.116372*Beta)
Best wishes
Torsten.

Accedi per commentare.

Risposte (1)

Star Strider
Star Strider il 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');

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by