Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
lsqcurvit question

Subject: lsqcurvit question

From: Nic Roberts

Date: 14 May, 2011 12:13:02

Message: 1 of 7

Hi
I am using lsqcurvefit to model an exponential like curve that starts at (0,0). My problem is that when I plot the lsq-fitted function I notice that it doiesnt start at (0,0).

Is there a way of making this a necessary condition of the curve fit?

Thanks

Nic

Subject: lsqcurvit question

From: Alan Weiss

Date: 16 May, 2011 11:58:21

Message: 2 of 7

On 5/14/2011 8:13 AM, Nic Roberts wrote:
> Hi I am using lsqcurvefit to model an exponential like curve that starts
> at (0,0). My problem is that when I plot the lsq-fitted function I
> notice that it doiesnt start at (0,0).
>
> Is there a way of making this a necessary condition of the curve fit?
>
> Thanks
>
> Nic

That's an interesting question. I can think of two possible solutions:

1. Reformulate your problem for fmincon (I mean, take the sum of squares
of the residual as your objective function) and give fmincon a nonlinear
equality constraint (the point (0,0) is on the resulting path)

2. Figure out a parameterization of your problem so that, with that
parameterization, every solution passes through the point (0,0). Use
lsqcurvefit on the reparameterized problem.

Good luck,

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: lsqcurvit question

From: Nic Roberts

Date: 21 May, 2011 15:54:04

Message: 3 of 7

Alan Weiss <aweiss@mathworks.com> wrote in message <iqr3gt$hc2$1@newscl01ah.mathworks.com>...
> On 5/14/2011 8:13 AM, Nic Roberts wrote:
> > Hi I am using lsqcurvefit to model an exponential like curve that starts
> > at (0,0). My problem is that when I plot the lsq-fitted function I
> > notice that it doiesnt start at (0,0).
> >
> > Is there a way of making this a necessary condition of the curve fit?
> >
> > Thanks
> >
> > Nic
>
> That's an interesting question. I can think of two possible solutions:
>
> 1. Reformulate your problem for fmincon (I mean, take the sum of squares
> of the residual as your objective function) and give fmincon a nonlinear
> equality constraint (the point (0,0) is on the resulting path)
>
> 2. Figure out a parameterization of your problem so that, with that
> parameterization, every solution passes through the point (0,0). Use
> lsqcurvefit on the reparameterized problem.
>
> Good luck,
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Hi Alan thanks for you response.

I am unfamilar with 'fmincon' do I use it in the same manner as 'lsqcurvefit'? I am looking through the help file but am getting confused. What is meant by a nonlinear inequality constraint?

Also I am unsure what you mean by parameterisation. I am running the lsqcurvefit to obtain a set of parameters for a mathematical model of some real world data, is this what you mean?

Thanks

Nic

Subject: lsqcurvit question

From: John D'Errico

Date: 21 May, 2011 19:51:04

Message: 4 of 7

"Nic Roberts" wrote in message <iqlrke$oul$1@newscl01ah.mathworks.com>...
> Hi
> I am using lsqcurvefit to model an exponential like curve that starts at (0,0). My problem is that when I plot the lsq-fitted function I notice that it doiesnt start at (0,0).
>
> Is there a way of making this a necessary condition of the curve fit?


Yes, there often is, but in order to help you more, we need
to know more about your model.

For example, is there a constant term in it? What is the exact
form of the model?

John

Subject: lsqcurvit question

From: Nic Roberts

Date: 22 May, 2011 15:33:05

Message: 5 of 7

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <ir9538$9td$1@newscl01ah.mathworks.com>...
> "Nic Roberts" wrote in message <iqlrke$oul$1@newscl01ah.mathworks.com>...
> > Hi
> > I am using lsqcurvefit to model an exponential like curve that starts at (0,0). My problem is that when I plot the lsq-fitted function I notice that it doiesnt start at (0,0).
> >
> > Is there a way of making this a necessary condition of the curve fit?
>
>
> Yes, there often is, but in order to help you more, we need
> to know more about your model.
>
> For example, is there a constant term in it? What is the exact
> form of the model?
>
> John

Hi John,

Its a model of the biaxial stress-strain behavour of a fibre embedded hyper elastic membrane. I have two stress-strain curves for the stress response of the membrane in the two directions of interest (lets call them x and y) and am trying to fit an exponetial like function to the curves.

options=optimset('MaxFunEvals',1e6,'MaxIter',1e6,'TolFun',1e-25,'TolX',1e-20);
xdata=[c_stretch r_stretch];
ydata=[c_stress r_stress]/0.5e-3;
x0=[10; 10; 10; 10; 10; 10];
[x,resnorm]=lsqcurvefit(@Constit,x0,xdata,ydata,[],[],options)

function Ein=Constit(x,xdata)
F_11=xdata(:,1); % x direction
F_22=xdata(:,2); % y direction
p=x(1)+x(2)*(F_11.^2+F_22.^2);
% Stress due to embedding substance
Moon11=x(1)+x(2)*(F_22.^2+1/(F_11.^2*F_22.^2));
Moon22=x(1)+x(2)*(F_11.^2+1/(F_11.^2*F_22.^2));
% Stress due to fibre stretch
Walpha=x(3)*x(4)*exp((x(4)/2)*(F_11.^2-1));
Wbeta=x(5)*x(6)*exp((x(6)/2)*(F_22.^2-1));
% Lagrangian multiplier to enforce incompressiblity
p=x(1)+x(2)*(F_11.^2+F_22.^2);
% Total directional stress
S11x=Moon11+Walpha-p;
S22x(i)=Moon22+Wbeta-p;
Ein=[S11x S22x];

Does this help?

Nic

Subject: lsqcurvit question

From: Nic Roberts

Date: 22 May, 2011 16:16:03

Message: 6 of 7

Sorry there were anumber of typos in the code here it is again,

options=optimset('MaxFunEvals',1e6,'MaxIter',1e6,'TolFun',1e-25,'TolX',1e-20);
xdata=[c_stretch r_stretch];
ydata=[c_stress r_stress]/0.5e-3;
x0=[10; 10; 10; 10; 10; 10];
[x,resnorm]=lsqcurvefit(@Constit,x0,xdata,ydata,[],[],options)

function Ein=Constit(x,xdata)
F_11=xdata(:,1); % x direction
F_22=xdata(:,2); % y direction
% Stress due to embedding substance
Moon11=x(1)+x(2)*(F_22.^2+1/(F_11.^2*F_22.^2));
Moon22=x(1)+x(2)*(F_11.^2+1/(F_11.^2*F_22.^2));
% Stress due to fibre stretch
Walpha=x(3)*x(4)*exp((x(4)/2)*(F_11.^2-1));
Wbeta=x(5)*x(6)*exp((x(6)/2)*(F_22.^2-1));
% Lagrangian multiplier to enforce incompressiblity
p=x(1)+x(2)*(F_11.^2+F_22.^2);
% Total directional stress
S11x=Moon11+Walpha-p;
S22x=Moon22+Wbeta-p;
Ein=[S11x S22x];

Subject: lsqcurvit question

From: Alan Weiss

Date: 23 May, 2011 14:39:12

Message: 7 of 7

On 5/21/2011 11:54 AM, Nic Roberts wrote:
> Alan Weiss <aweiss@mathworks.com> wrote in message
> <iqr3gt$hc2$1@newscl01ah.mathworks.com>...
>> On 5/14/2011 8:13 AM, Nic Roberts wrote:
>> > Hi I am using lsqcurvefit to model an exponential like curve that
>> starts
>> > at (0,0). My problem is that when I plot the lsq-fitted function I
>> > notice that it doiesnt start at (0,0).
>> >
>> > Is there a way of making this a necessary condition of the curve fit?
>> >
>> > Thanks
>> >
>> > Nic
>>
>> That's an interesting question. I can think of two possible solutions:
>>
>> 1. Reformulate your problem for fmincon (I mean, take the sum of
>> squares of the residual as your objective function) and give fmincon a
>> nonlinear equality constraint (the point (0,0) is on the resulting path)
>>
>> 2. Figure out a parameterization of your problem so that, with that
>> parameterization, every solution passes through the point (0,0). Use
>> lsqcurvefit on the reparameterized problem.
>>
>> Good luck,
>>
>> Alan Weiss
>> MATLAB mathematical toolbox documentation
>
> Hi Alan thanks for you response.
> I am unfamilar with 'fmincon' do I use it in the same manner as
> 'lsqcurvefit'? I am looking through the help file but am getting
> confused. What is meant by a nonlinear inequality constraint?
>
> Also I am unsure what you mean by parameterisation. I am running the
> lsqcurvefit to obtain a set of parameters for a mathematical model of
> some real world data, is this what you mean?
>
> Thanks
>
> Nic

For explanations of including nonlinear constraints, see
http://www.mathworks.com/help/toolbox/optim/ug/brhkghv-11.html#brhkghv-16
For your problem you would take c = [] and ceq as the equation that
makes the curve start at (0,0).

For examples using fmincon, see
http://www.mathworks.com/help/toolbox/optim/ug/brn4nh7.html

Alan Weiss
MATLAB mathematical toolbox documentation

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us