fit pressure temperature data in antoine equation using the command lsqnonlin

I want to fit pressure temperature data in antoine equation using the command lsqnonlin.The objective function is the minimization of the data available and data computed using the equation.The parameters of the equation are estimated after the minimization is done using this command.
Pressure=[1 5 10 20 40 60 100 200 400 760]
temp=[-59.4 -40.5 -31.1 -20.8 -9.4 -2.0 7.7 22.7 39.5 56.5]
Antoine eqaution:
ln P=A+B/(T+C)
where A,B and C are the parameters to be estimated. I am not able to write the function file properly.When i call the function file to the command lsqnonlin ,it shows error. help on the use of this command with the mention of the function file

3 commentaires

We need to see what you did in order to correct the error. We also need to see the error, copy/pasted.
function f = Antoine(c0)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
x=[-59.4 -40.5 -31.1 -20.8 -9.4 -2.0 7.7 22.7 39.5 56.5];
y=[1 5 10 20 40 60 100 200 400 760];
for i=1:10
Y(i)=exp(c0(1)+(c0(2)/(x(i)+c0(3))));
end
for i=1:10
f(i)=[(Y(i)-y(i))/0.02];
end
end
and the run file goes as follows
c0=[4 1300 -30];
f=lsqnonlin(Antoine,c0);
error is Error using Antoine (line 7) Not enough input arguments.

Connectez-vous pour commenter.

 Réponse acceptée

First, lsqnonlin isn’t primarily intended for curve fitting. The lsqcurvefit function is, so use it instead.
I restated your ‘Antione’ function as a more convenient ‘anonymous function’, and used lsqcurvefit:
x=[-59.4 -40.5 -31.1 -20.8 -9.4 -2.0 7.7 22.7 39.5 56.5];
y=[1 5 10 20 40 60 100 200 400 760];
Antoine = @(c0,x) exp(c0(1)+(c0(2)./(x+c0(3))));
c0 = ones(3,1);
C0 = lsqcurvefit(Antoine, c0, x, y)
to produce:
C0 =
5.1897e+000
3.8765e+000
1.9997e+000

7 commentaires

Thank you for your answer.I dont understand that why that error was being detected.input arguments were enough i suppose.If possible, pls elaborate on it as well.Plus the paper I am reading by Ross Swaney and James Rawlings include parameter estimation using the command lsqnonlin for fitting the model.
If I remember correctly, the lsqnonlin function appeared some versions before lsqcurvefit appeared, as a ‘wrapper’ around lsqnonlin to make it easier to do curve fitting. It also generates useful statistics that can be used by the Statistics Toolbox functions to calculate confidence intervals on the parameters and the fit. To use lsqnonlin for curve fitting, it is necessary to add a sum-of squares error function, such as:
OLS = @(b) sum((y - Antione(b,x)).^2);
then call lsqnonlin as:
C0 = lsqnonlin(OLS, c0)
I’ve not done that with lsqnonlin because lsqcurvefit exists and is easier to use. I have done it with fminsearch.
As for the anonymous functions, I simply find them easier to use than function files. They also take up significantly less disk space, and can be used inside ordinary script files. Function files have to be separate from the script file that calls them.
thank you for your answer. I will try this command as well.but command lsqnonlin already has inbuilt capability of squaring the error. Anyways thanks for the support
My pleasure!
I just now discovered what likely threw the error in your call to lsqnonlin. If you have one of the more recent MATLAB releases, and your Antoine function is a separate function file (as it seems to be), you need to create a function handle in your argument to lsqnonlin:
c0=[4 1300 -30];
f=lsqnonlin(@Antoine,c0);
Note the added ‘@’ sign. That may solve your problem. I apologise for not picking up on that earlier. I take comfort in that I wasn’t the only one who missed it.
hey thanks!!!! yeah thats obvious... missed it :)
Again, my pleasure!
I still recommend lsqcurvefit for the sort of study you’re doing. Easier.

Connectez-vous pour commenter.

Plus de réponses (2)

Carsten
Carsten le 7 Juil 2014
Modifié(e) : Carsten le 7 Juil 2014
I don't think that this is the solution for the problem. If i use the C0 values to calculate the antoine equation, it doesn't fit the given data.
x=[-59.4 -40.5 -31.1 -20.8 -9.4 -2.0 7.7 22.7 39.5 56.5];
y=[1 5 10 20 40 60 100 200 400 760];
Antoine = @(c0,x) exp(c0(1)+(c0(2)./(x+c0(3))));
c0 = ones(3,1);
C0 = lsqcurvefit(Antoine, c0, x, y)
ant=exp(C0(1)+(C0(2)./(x+C0(3))));
figure
hold on
grid
set(gca,'FontSize',14)
plot(x,y,'b');
plot(x,ant,'r');
This method is highly sensitive to initial guess.
Try this:
A = 10;
B = -2000;
C = 200;
c0 = [ A; B; C ];

1 commentaire

This method is highly sensitive to initial guess.
That is a characteristic of all nonlinear parameter estimation techniques. In the eight years since this appeared, I now routinely use the ga and similar approaches in the Global Optimization Toolbox to determine the best parameter estimates. It helps to know the approximate parameter magnitudes and ranges at the outset to be certain the estimated parameters are realistic.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by