Least-squares fitting a square pulse
I am trying to fit a square pulse to data in the least-squares sense in Matlab. The parameters that are being optimized are the height, start, and end - x(1), x(2) and x(3) in the program, respectively. However, the least-squares program is only varying the height, for some reason. Why is this occurring? How else could I fit a square pulse using least-squares?
Although in this example the pulse would be easy to fit by inspection, for the purpose of my project, it is not an option.
ydata=-.05+.1*rand(1,numel(xdata))+heaviside1(xdata-1)-heaviside1(xdata-4);...Adding constraints to linear fit parameters of separable least squares fit
I was wondering if anyone can help me to figure out how to add equality and inequality constraints to the linear parts of a separable least squares fit. I saw fminspleas is able to do it for the nonlinear fit parameters (using transformations from a constrained problem to an unconstrained one), but not for the linear fit parameters. Here is my code for the separable least squares fit. Thanks.
f...Least square fitting
I have this graph:
x = [0.000235 0.00025 0.0003 0.0004 0.0005 0.0006 0.00075]
y = [54.9 43.1 62.7 86.3 86.3 90.2 96.1]
plot (x, y)
ylabel ('Correct Detection [%]')
legend ('Psychometric Function')
and I want to fit it to this equation:
P(A, 'theta') = [1/sqrt(2*pi*sigma²)] * integral e^-[(A-'theta'²)/2*sigma²]
how can i do this?
"xety89 " <firstname.lastname@example.org> wrote in message <email@example.com>...
> I have this graph...Least squares fitting
I am working on an inverse problem where I need to use least squares fitting.
I am working on characterization of impedance of a piezoelectric crystal. A PZT crystal can be modeled as a series RLC circuit in parallel with a parasitic capacitor. Thus, I can derive the transfer function of its impedance and admittance and simulate it (see the code below)
I am trying to extract R,L,C and C0 parameters from this simulated admittance curves using least squares fitting method.( Also, I need to inversely calculate these from the admittance curves that are constructed using ...Least Square Fit
I tried to use lsqlin to do a least square fit with 3 constraints. I
had 7 variables. However it didn't seem to take into account the last
I am trying to use fmincon but keep getting an error 'Inner matrix
dimensions must agree'- I checked the dimensions of the constraint
and Obj function matrices.but Ican't figure out why this is
In article <firstname.lastname@example.orgYaTP>,
"Shar P" <email@example.com> writes:
>I tried to use lsqlin to do a least square fit with 3 constraints. I
>had 7 variables. However it ...least square fit
I have the following data file:
Now I want to do a least square fit on the data of the first and
second column. The data in the first-column represent the x-values, the
data in the second column represent the y-values. I don't need the rest
of the columns.
Now I now that x and y are related somehow as:
y = a/(x**b)
and I want to find a and b as accurate as possible.
The file that plots my data to an .eps file is at
If I don't specify an initial value for b_sob, the fit fails. If I do
specify a starting value of 0.9 the fit works, but the result is not
satisfying as can be seen from the .eps file at
I have also tried to fit on log($2)=a-b*log($1) and then plot
exp(a)/(x**b) but this didn't give me satisfying results either.
How can I increase the quality of my fit?
"Share what you know. Learn what you don't."
Bart Vandewoestyne wrote:
> I have the following data file:
> Now I want to do a least square fit on the data of the first and
> second column. The data in the first-column represent the x-values, the
> data in the second column represent the y-values. I don't need the rest
> of the columns.
&...least square fit
I have many file with extension (.dat). I need to open them in IDL and
have least square fit.
Is any one have idea on who to that.
> I have many file with extension (.dat). I need to open them in IDL and
> have least square fit.
> Is any one have idea on who to that.
Well, rest assured, the code will be less than 10 lines
long. But, *which* 10 lines will depend on more details.
What do you know about this problem?
You can find a lot of hints at the web page below.
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote'...Least square fitting
I have a problem with a rather complicated function depending on four
parameters which I try to find using least square fitting and I don't
know exactly how to do it.
The basic problem is the following:
I have an astronomical image of a star field and try to relate the sky
coordinates (right ascension, declination) of the stars to the pixel
coordinates (x, y).
The function to relate the two depends on the not accurately known
parameters focal length of the lens (f), the rotation of the field of
view with respect of the north direction (beta) and the center sky
coordinates of the...least squares fit
I'm trying to solve a system of 5+ equations for 3 unknowns,
preferably using the least-squares method. I've Solve will not
return solutions for more equations than you have unknowns. Fit does
not work because my equations have 4 sets of data.
Si=a*Ui + b*Vi + c*Wi, where i goes from 1 to 5
U, V, and W all come from a table, and S is from experimental data.
I need to know how to solve for a,b,c given more than 3 equations.
Background: The problem is actually trying to solve for Judd-Ofelt
parameters of a laser crystal. S is the experimental line strength and
U, V...least square fit #4
I tried to fit data to get the sig and mean parameters of the
gaussian distribution. I found lsqcurvefit can only get the correct
fitting result of sig but not for the mean. The mean is always the
initial value you set for the fitting.
Any input is highly appreciated.
My code is very simple. Is there something wrong with it?
options=optimset('MaxFunEvals',1000,'MaxIter&...Least squares fit with matrices
I have equation:
where size(Y_n)=size(X)=[100 100] and size(a_n)=[1 1]
X and Y_n are constants
How can I do some kind of least squares fit to determine a_n?
> I have equation:
> where size(Y_n)=size(X)=[100 100] and size(a_n)=[1 1]
> X and Y_n are constants
> How can I do some kind of least squares fit to determine a_n?
A = [Y1(:),Y2(:),Y3(:)]\X(:);
...Least squares fitting #2
I need to find the coefficients k1-k6 of the following equation:
P = G*(k1 + k2*T + k3*log(G) + k4*(log(G)).^2 + k5*T*log(G)+
The experimental data I have are P, G and T.
Is there any MATLAB function in order to obtain the
coefficients using least-squares fitting?
Do I need the Curve Fitting Toolbox?
Thank you very much,
"Zaira " <Zaira.Girbau-Garcia@jrc.it> wrote in message
> I need to find the coefficients k1-k6 of the following equation:
> P = G*(k1 + k2*T + ...Least square plane fitting
i'm a student of University of Parma (Italy), and i've the following
I've found in internet the following model for fitting a plane from a
cloud of point 3D.
The link to the page is [ http://www.bmm.icnet.uk/people/suhail/plane.html
I've implemented this model in C++ and i've obtained some good result
but when i try to reconstruct the passages of the procedure i'm not
able to obtain the resulting matrix 3x3 denoted as W in the follow.
I want to know if something one can help me to resolve this problem.
I've tried to contact the author of the mod...Least Squares Fitting #3
I am in need of some help. I am fitting Gaussian curves using the curve fitting toolbox. Once I fit the curve I get a x_0 centroid and a width. My goal is to fit the centroids of five different curves. I would like to fit the following and generate a slope and intercept. I am unable to do this is MATLAB.
x y upper_y lower_y
..511 108 109.4 107.3
1.275 280 283 280
.... ..... ..... .....
.... ..... .....
so on and so ...Weight least square fit
A quick description of my problem:
I have 4 sensor measurements (x_sensor), which can be estimated using a numerical model (nb the model is nonlinear is solved numerically...)
I wish to fit the parameters of my model to best represent the measured data by performing a weighted least square fit with a different weighting for each sensor (due to different noise in the measurements). i.e. an objective function:
error = A(x1_sensor - x1_model) + B(x2_sensor - x2_model) + C(x3_sensor - x3_model) + D(x4_sensor - x4_model)
I am currently using lsqcurvefit but get a bad fit due to so...Which is the fastest least squared fit?
I have a program that fits measured data to a function with a least squares fit. The measured data contains about 30 data points, and the fitting function has 5 parameters in total:
y(x) = c1 * cos(c2*x + c3) * sin(c4*x)/x * exp(- c5*x)
I also want to apply boundaries to the constants. I have tried several fitting algorithms, e.g. fminsearch and lsqnonlin. The trouble is, that since the fit is performed several thousands of times each time the program is executed, it is important that the function provides a fast fit. I have discovered that lsqnonlin is faster than fminsearch, but execution ...Least Squares Surface Fitting
I'm a beginner of Matlab using.
I have to find out how to fit a surface of 2 dimensional scatterd
data in a least squares sense.
Are there alreay toolboxes or functions to provide that?
Can anybody help and give me more information?
Thankx a lot
> Dear all,
> I'm a beginner of Matlab using.
> I have to find out how to fit a surface of 2 dimensional scatterd
> data in a least squares sense.
> Are there alreay toolboxes or functions to provide that?
> Can anybody help and give me more information?
> Thankx a l...Least square curve fitting
I need some help with a curve fitting problem for data points.
I have a set of data points
g=[g1 g2 g3 g4 g5]
h=[h1 h2 h3 h4 h5]
and would like to fit these data to an equation y=ax/(b+x)
in least square sense, with initial guesses a=170 and b =
1000 until R2 correlation is 95%.
"Alison " <firstname.lastname@example.org> wrote in message
> Hi all,
> I need some help with a curve fitting problem for data
> I have a set of data points
> g=[g1 g2 g3 g4 g5]
> h=[h1 h2 h3 h4 h...least-squares fit with constraint
Hi, Is there a way in Matlab to perform a least-squares fit on a column vector, with the constraint that the slope is zero?
I have a column vector of periods extracted from an periodic waveform, and I'm trying to find the average period, where "average period" is defined as that period having the best least-squares fit.
If I run p=polyfit(x,y,1), it will return a line having a slope (albeit a small slope). Anyway to do something similar but constrain the LSF operation that the slope must be zero?
Thanks in advance
On Thu, 2 Dec 2010 01:28:05 +0000 (UTC), "gkk gk...nonlinear least squares fit
I am trying to solve an optimization problem in Matlab. It is a nonlinear least squares problem. The goal is to derive the best-fit equations of seven straight lines (and other standard output e.g. residuals etc.).
I've posted the problem description, and two images, one that describes the problem setting in detail, the other showing the set of 3D points I plotted for this, all here::
Since I never used any optimizer before, I'd truly appreciate if you can help on:
1.which Matlab function to use for the problem
2.what f...Nonlinear least squares fitting
I was wondering if it is possible to use lsqcurvefit to fit input
data given multiple observables? That is, if I have two observables,
y1 and y2, each effected differently by input variables x1, x2 and
x3, can I use lsqcurvefit to obtain values for x1, x2, and x3?
> I was wondering if it is possible to use lsqcurvefit to fit input
> data given multiple observables? That is, if I have two
> y1 and y2, each effected differently by input variables x1, x2 and
> x3, can I use lsqcurvefit to obtain values for x1, x2, ...Least square surface fitting
I'm new to Matlab
I need to fit a surface to my observed data in order to
find a polynomial equation of the surface.
I have (x,y,z) data.
Can anyone help me on this.
"Hashika " <email@example.com> wrote in message
> Hi all,
> I'm new to Matlab
> I need to fit a surface to my observed data in order to
> find a polynomial equation of the surface.
> I have (x,y,z) data.
> Can anyone help me on this.
polyfitn, from the file exchange.
http:/...least squares curve fit
Hi I'm trying to write a program that takes data points and solves
for coefficients for a least squares curve fit using matrices and
starting from an initial condition. I tried building the coefficient
matrix and solving for the coefficients but I end up with a straight
line. Any advice would be appreciated.
In article <firstname.lastname@example.orgYaTP>,
"John Roth" <email@example.com> writes:
>Hi I'm trying to write a program that takes data points and solves
>for coefficients for a least squares curve fit using matrices and
which type of curve ?
which type...NonLinear least square fit
Iam using the lsqcurvefit function to estimate some parameters by
fitting a kinetic model to experimental data.I need to get an
estimate of the errors for the individual parameters that are
calculated by the program.The function lsqcurvefit returns residuals
but does not provide any estimates for the standard deviations for
the parameters calculated.Iam sure there is a way of calculating
them.Can someone please help?
Farah Bardai wrote:
> Iam using the lsqcurvefit function to estimate some parameters by
> fitting a kinetic model to experimental data.I need to get an