cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Curve Fitting - F1

wzelik
12-Amethyst

Curve Fitting - F1

Dear Collab Users

I need urgently fitting equation for nonlinear curve.
Could you advice me?
I tried to find similar exapmples into the history of forum unfortunately without success.

W. Zelik

ZMR
POLAND
64 REPLIES 64
RichardJ
19-Tanzanite
(To:wzelik)

On 1/5/2010 4:45:58 AM, wzelik wrote:
>Thank you once again.
>I think that it is what I
>want.

Maybe. But it's generally a good idea to check a fitted function with finer x-spacing than the original data points (I didn't bother in the sheet I posted because each segment is just a simple polynomial, so it's obvious what the curve does between data points). If you are fitting a rational polynomial it's not just a good idea, it's essential. A rational polynomial has poles, and you need to know if any are in the range of the data. Because your data is discontinuous in it's derivatives you also need to check what the fit is doing at those sudden slope changes, because overshoot can be a problem (this is also true for spline interpolation). Lastly, you have flat line segments, and you need to check what the polynomial is doing in those regions. See the attached sheet.

You data is continuous, but discontinuous in it's derivatives. The best function to fit that is one that is also continuous, but discontinuous in it's derivatives. That's why I chose the piecewise polynomial (note that a rational polynomial is discontinuous in it's derivatives, but the function itself is also discontinuous). The piecewise polynomial will also give you the lowest total number of coefficients that accurately fit the curve. Take column 2 as an example (see the sheet I posted). The first section is just a constant. You must have at least one coefficient to describe it. The second section and the fourth section both have a slope and some curvature. You need at least three coefficients to describe those: one for the offset, one for the slope, and one for the curvature (i.e. a quadratic). The third section also has a change in curvature, so requires at least 4 coefficients. For all but the first section one coefficient is removed because the polynomials are forced to be continuous, leaving a total of only 8 coefficients for the polynomials. In addition to those there is one for each knot position, so 11 total, for a very good fit. In addition, you can actually get some physical meaning out of some of those coefficients, especially the knot positions.

>If you have any sugestion
>about surface fitting I will
>be apreciated.

Because your data is not continuous in it's derivatives that will be diffucult (which is why I don't have the time to do it). For the 2D case the sudden slope changes occur at single points: the knot positions in the fit. When you have a surface the sudden slope changes occur along a curve, which makes things much more difficult. If you project that curve into the x-y plane you can describe it by some function y=f(x). Note that the function may not be single valued, which further complicates things. If you fit the surface with piecewise polynomial surfaces, then they must meet along that curve (or curves, if there are more than two sections to the surface). If you allow the function f to take any form that will not be possible, although it might be possible to make the polynomials approximately meet to within some acceptable error. However, I think (but am not sure) that if you make the function f a polynomial (preferably a low order polynomial) it will be possible to make the polynomial surfaces meet exactly: it's just an extension of what I did in the worksheet I posted. Making that work in practice would not be easy though!

An alternative approach might be to fit all the columns. Then take the knot positions as a function of Al2O3 and fit them to polynomials. Take the coefficients for each polynomial segment, and do the same. Then you can replace each coefficient in the x-y polynomials with a polynomial in z:

So as an example, take a straight line: y=a*x+b. The coefficients a and b are different for different columns of data (i.e. in the z direction)

Fit a and b vs z to get polynomials a(z) and b(z)

Replace the equation for the line with

y=a(z)*x+b(z).

Richard
wzelik
12-Amethyst
(To:RichardJ)

Dear Richard

Once more I have got very interesting informtion
from you. I have to think it over.
...
Big thank you for your explanations.

W. Zelik

Yes, you are right.

Instead of changing things, you can just re-adjust the parameters P & Q in the rational fraction to better values after making the glitch check at the end. This has to be done for each column selected.

I printed a "RemToDo" in my mind on that one as it finally seems interesting, especially because Theodore and myself are very versed in that stuff of rational approximations.

jmG

Yes, you are right.

Instead of changing things, you can just re-adjust the parameters P & Q in the rational fraction to better values after making the glitch check at the end. This has to be done for each column selected.

I moved the glitch check up into the docment.
RichardJ
19-Tanzanite
(To:RichardJ)

On 1/5/2010 9:19:09 AM, rijackson wrote:

>An alternative approach might be to fit
>all the columns. Then take the knot
>positions as a function of Al2O3 and fit
>them to polynomials.

Some more thoughts on this. I expect that for each section of the surface you could get a good fit with a low order 2D polynomial. If that's the case, then maybe making the polynomials match at the boundaries is overkill. If the fit is good, then they will be very close anyway, and maybe that is good enough for what you want. The regress function can be used to fit 2D polynomials to each section of the surface, so that part is easy. You can find the boundaries for sections from the worksheet I posted, as described above. So the only remaining part of the problem is to write a program that determines which section a given x,y coordinate is in. Then you can split all the data into different sections, and fit each section using regress.

Richard
wzelik
12-Amethyst
(To:wzelik)

I reviewed POLAND12.mcd once again.
I don't have any remarks to mathematical aprroach,
but I don't fully understand meaning of parameter
"A" in the expression vy:=SL+A.

W. Zelik

A is the bulk amount of Al2O3 added to the batch.

Is not necessary to add Al2O3 to SL data because we
consider results of reaction:

SL series

A:=1,1...29
col(0)=(30-A)/A
col(1)=(30-A)CaO + (A)SiO2 + (0)Al2O3 + 70MgO
col(2)=(30-A)CaO + (A)SiO2 + (5)Al2O3 + 70MgO
col(3)=(30-A)CaO + (A)SiO2 + (10)Al2O3 + 70MgO
...
col(8)=(30-A)CaO + (A)SiO2 + (35)Al2O3 + 70MgO

by weight (gram)


W. Zelik

Well, in that SL case, just add A = 0 to the mix. Then process and check for glitches by varying the parameters P & Q on the rationl fraction panel.

Sorry I can't keep up with you.

On 1/5/2010 1:14:31 PM, wzelik wrote:
>Is not necessary to add Al2O3
>to SL data because we
>consider results of reaction:
...
>W. Zelik
______________________________

No need to tell collabs what they should do or not. If you have data from experiments, just post them for curve fitting, that means post them again with what you didn't disclose in the 40 messages. I will look at it (next week) in case some models hadn't been explored yet and the thread not exhausted.

jmG



wzelik
12-Amethyst
(To:ptc-1368288)

It was not my intention offend anybody.
I aprreciate very much what collab users did for
solving this problem.

W. Zelik


wzelik
12-Amethyst
(To:wzelik)

As I wrote source of data is a Thermochemistry
system (FACTSAGE v. 6.1).
It is results of calculation from posted reaction
only.
I did not carry out any experiment.
I received two series of data: (1) SLAG amount, (2)
MgO saturation solubility.
I posted on forum one of them (SL (slag))and tried
explain what is it and what I want.
I counted for yours assistance mainly in 2D fitting
and I got it. Thank you!


W. Zelik
RichardJ
19-Tanzanite
(To:ptc-1368288)

On 1/6/2010 1:28:34 PM, jmG wrote:

>No need to tell collabs what they should
>do or not.

If they do something wrong, it's worth pointing it out.

>If you have data from
>experiments, just post them for curve
>fitting, that means post them again with
>what you didn't disclose in the 40
>messages.

It is posted.

Richard

I have tried a few other models. Fast Fourier and FFTe do not work due to the discontinuity. A reciprocal power series is OK but not so accurate. The proposition by Inzzynier Zelik for a surface plot is unreasonable. His firm manufactures refractory materials and a surface plot does nothing to aid that design process.





I have improved the document slightly with a log transform of the y-data and made provision for a cubic spline to check data by reverse sorting the SL matrix. In this, A can refer to your adding A = 70 MgO to the parent mix.

Superceding all previous attempts on the SL data , the following 2 worksheets represent (a) an exportable model fit PX1.MCD, and (b) a fixed, simple, non-exportable cspline fit PX9.MCD.

A ternary plot, ternary graph, triangle plot, simplex plot, or de Finetti diagram is a barycentric plot on three variables which sum to a constant. It graphically depicts the ratios of the three variables as positions in an equilateral triangle. It is used in petrology, mineralogy, metallurgy, and other physical sciences to show the compositions of systems composed of three species. In population genetics, it is often called a de Finetti diagram. In game theory, it is often called a simplex plot.

IS THIS WHAT YOU WANTED DONE? You can look up de Finetti diagram on Wikipedia for instructions.

On 12/29/2009 4:19:58 AM, wzelik wrote:
>Dear Collab Users
>
>I need urgently fitting
>equation for nonlinear curve.
...
>
>W. Zelik
>
>ZMR
>POLAND
_______________________________

I read all the comments, will be Mathcadless till mid january 2010. Understanding Theodore comment about smoothing the collected data, I will try my own tools, just in case. If a functional relationship could be concluded ? maybe but as a monk project especially being remote from the lab experiments or results from the actual factory.

jmG

On 12/31/2009 7:25:35 AM, jmG wrote:
>On 12/29/2009 4:19:58 AM, wzelik wrote:
>>Dear Collab Users
>>
>>I need urgently fitting
>>equation for nonlinear curve.
>...
>>
>>W. Zelik
>>
>>ZMR
>>POLAND
>_______________________________
>
>I read all the comments, will be
>Mathcadless till mid january 2010.
>Understanding Theodore comment about
>smoothing the collected data, I will try
>my own tools, just in case. If a
>functional relationship could be
>concluded ? maybe but as a monk project
>especially being remote from the lab
>experiments or results from the actual
>factory.
>
>jmG
_______________________________________

This is the data set from Theodore. I understand nothing in there, except that each column could eventually be smoothed as well as the overall 3D plot. For your question if there is a possible family of fitting model, answer is "probably NO".

From that work sheet: what is it you want ?

jmG
wzelik
12-Amethyst
(To:ptc-1368288)

Thank you very much for your reply.
Your knowledge about Mathcad is huge but I’m slightly confused, because answer for your question:

>>>From that work sheet: what is it you want ?

…is unfortunately NO!

My intention was well understood by Richard and Tom. Theodore helped me also.

I know that this thread is very long.
That is why I don’t want to waste your time longer.
I received a few interesting files for analyses. It is enough for me.


>>>This is the data set from Theodore.
>>>I understand nothing in there…

I tried to explain what I want on the best way I can.
However if you want know about source of SL data I can prepare for you few screenshot from calculation pane (FactSage) and send you by email. Maybe would be easier!

W. Zelik

FactSage is a very voluminous software platform much used in the chemical societies and incomprehensible to most MathCad Forum members. It can develop mathematical models or even de Finetti ternary diagrams, I guess. It is not easy to shift a problem from FastSage to MathCad. Others in Europe tend to use Excel. There are many cards available in Europe for curve fitting in limited areas using both physiochemical and mathematical program descriptions.

It was pure mathematical question.
I have series of data and I need aproximation equation.
I think that Mathcad forum is suitable.

W. Zelik



wzelik
12-Amethyst
(To:wzelik)

I enclose a few screenshot and xls file for further explanation. I should do that on the beginning but please forgive me I did not expect any problem.
As I wrote I tried to obtain best approximation equation using Mathcad.
On the beginning I thought about 2D fitting (Slag amount as a function CaO/SiO2 and Al2O3=const).
Next after a few very interesting examples I asked about possibility of Surface approximation equation (Slag amount as a function of CaO/SiO2 ratio and Al2O3).
That’s enough.

W.Zelik



wzelik
12-Amethyst
(To:wzelik)

cont...



W. Zelik
wzelik
12-Amethyst
(To:wzelik)

wzelik
12-Amethyst
(To:wzelik)

and last one...

w.Zelik
AlvaroDíaz
12-Amethyst
(To:wzelik)

To adjust some data to a curve you need the data and the curve family.

In your case the data isn't experimental, it is intra or extrapolated data based also in a model (which gives the curve family) and some few experimental data points. But the origin of the calculus could be very complicated. Programs like FactSage starts with the EOS of pure substances and interaction matrix coefficients for mixtures; a model for mixtures, actually a function of the states, and a model for the equilibrium, reactions, etc.

But this isn't important, it's only to discard the curves family search based in how the data is obtained. So, your data are only that: points in some space, and you want a curve (or surface or anything) to adjust.

There are two kinds of curve fitting: situations where you want to assign a physical meaning to the obtained parameters, and sitations where you whant only reproduce the physical propertie under study to eval anywhere where you define as the domain, not only in the given points.

When you search a curve with few parameters you probably are more interesting in the physical meaning of those parameters. But this is not your case, so the number of parameters is not important, you can handle a lot of adjust parameters.

This is the case for the EOS in programs like REFPROP from NIST: they write polynomials with several parameters (usually in the range of 20-40 terms) to adjust the a function with variables T and P representing the EOS in some region for the substance. Sometimes this fuction is the volume, but not always.

In this case the "curve family" is a polynomial. But there are "theoretical" reasons to take polynomials: The algorithm to eval the function and they derivatives are very easy (Horner's method) and the error is easy to handle and take under control. The number of terms is given by the data pressicion and the -usually- fortran routines.

Programs like Hysys, which modelates also pure and mixed substance, have usually different EOS models for the same substance. One very general is the Peng-Robinson equations, with few parameters and a low level degree polynomial: only 3 roots, and only one with sense.

Even the paramaters for long equations can have some kind of interpretation as the virials of some model, they are enough complicated to not be used as a model representation, only in very high level texts, and are taken as pure mathematics expressions in the practice.

So, what you need to specify your "family curves" is first chose a short or a long model. You must to jusfify also your selection: for few parameters models you must to provide some physical interpretation of the parameters, and for several parameters model you must to study the numerical pressicion of your software and your hardware. This not meaning a fully study, only gives to the reader enough backgraund if it is needed.

Also there are avaible predefined models for properties like cp(T), thermal cond (T) and this kind of calculations that have "predefined" equations, numbered: eq 98, eq 102 and eq 104 are the more usual! This shorts models search only a way to interpolate values, but not assign physical sense to the parameters: isn't the purpose.

In resume: you must to search a family of curves and gives a few reasons to choose this. In the practice you can search in the literature which model choose another people and see why this is done.

Your work is complete when you provide a few justification of the general model (the curve family), the particular model (the parameters for the selected curve family) and the maximun relative or absolute error that the original data set is evaluated with your model. This last thing is very important, and can be evaluated as the maximun of the errors for each data point.

Regards. Alvaro.

On 1/11/2010 1:41:28 AM, wzelik wrote:
>It was pure mathematical
>question.
>I have series of data and I
>need aproximation equation.
>I think that Mathcad forum is
>suitable.
>
>W. Zelik
>____________________________

You keep talking about curve fitting but at message 59: nothing to see ! I mean no data set. This collab is a mine of curve fitting expertise and models. I have used Theodore data table, then make the one you want. 100's of fitting were done in this collab, none failed whether via interpolating methods or models as applicable.

Plug your *.xls in a Mathcad data table,
clean, sort and all what's needed in order to:
have a column of the independent and columns of the dependents.

jmG

Very tedious runs and hand copying coefficients for rational polynomial fits of the 8 columns of the SL data. The case here was SL loaded with 70 units of some additional ore. This is a fixed case, and not user manipulated. It was made to show a family of curves.
Announcements

Top Tags