Error Message: expression or statement is incorrect
Mostra commenti meno recenti
I'm trying to create a code for least squares curve fitting, but when I make the function handle to be evaluated in the command window, I keep getting this error message saying that the the expression is incorrect. Below is the code I've made along with the inputs in the command window:
command window:
Running Least Squares Method...
X-Values: [0 10 20 30 40 50 60 70 80 90 100 110]
Y-Values: [3589 4132 6307 7814 11842 18072 27542 33141 44337 55002 65660 76201]
Function: (@K, r, timedat) ((popdat(1) * K ) / (popdat(1) + (K - popdat(1)*exp(-r * timedat))))
Error using LeastSqMethod (line 13)
Error: Expression or statement is incorrect--possibly unbalanced (,
{, or [.
Code:
clear
clc
%% Step 1 - Inputting Data
disp('Running Least Squares Method...');
disp(' ');
timedat = input('X-Values: '); % Array of X Values (Time)
popdat = input('Y-Values: '); % Array of F(x) Values (Population)
func = input('Function: '); % Function to be evaluated
x0 = input('Initial Guess: ');
%% Step 2 - Least Squares Fit Determination
fit = lsqcurvefit(func, x0, timedat, popdat)
%% Step 3 - Plotting Results
xrange = input('Enter X-Value Range: ');
plot(timedat,popdat,'ko',xrange,func(fit,xrange),'b-')
legend('Given Data', 'Model Fit')
xlabel('Time (Years)')
ylabel('Population')
title('Population Growth in Bryan, TX')
grid on
1 Commento
Walter Roberson
il 15 Dic 2018
the @ has to go before the (
@(K,r,timeout) .....
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
