Function returning matrix instead of vector

4 visualizzazioni (ultimi 30 giorni)
Hello,
I have made a function for use in least squares curve fitting of the form:
f=@(xf,xdata)xf(1)*(xf(4)+((xf(2)-xdata)/(xf(3)/2))).^2/(1+((xf(2)-xdata)/(xf(3)/2)).^2)
xf should have 4 parameters
When I test the function with
f(x0f,xdata)
with x0f = [1.0000, 462.7580, 1.8007, 0], and xdata a 15x1 column vector I get a 15x15 matrix as output, when I expect a 15x1 column vector. I believe the issue is that the f function has xdata squared (.^2) both in the numerator and denominator, but I don't know how to circumvent this as there is no way to isolate xdata. Any help is appreciated.
  1 Commento
Travis Craddock
Travis Craddock il 17 Giu 2020
P.S. Entering this function into lsqcurvefit results in an error "Function value and YDATA sizes are not equal."

Accedi per commentare.

Risposta accettata

KSSV
KSSV il 17 Giu 2020
Modificato: KSSV il 17 Giu 2020
Read about element by element operations.
Repalce * with .*, / with ./
f=@(xf,xdata)xf(1)*(xf(4)+((xf(2)-xdata)./(xf(3)/2))).^2./(1+((xf(2)-xdata)./(xf(3)/2)).^2) ;

Più risposte (1)

Rafael Hernandez-Walls
Rafael Hernandez-Walls il 17 Giu 2020
f=@(xf,xdata)xf(1)*(xf(4)+((xf(2)-xdata)/(xf(3)/2))).^2./(1+((xf(2)-xdata)/(xf(3)/2)).^2)

Categorie

Scopri di più su Curve Fitting Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by