"Orchid Bee" <orchidbee08@yahoo.com> wrote in message <gjbhvh$9h$1@fred.mathworks.com>...
> "Jiro Doke" <jiro.doke@mathworks.com> wrote in message <gjbgeq$sej$1@fred.mathworks.com>...
> > "Orchid Bee" <orchidbee08@yahoo.com> wrote in message <gjbdu6$ocp$1@fred.mathworks.com>...
> > > "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gjbcj3$2j5$1@fred.mathworks.com>...
> > > > "Orchid Bee" <orchidbee08@yahoo.com> wrote in message <gjbb62$7dg$1@fred.mathworks.com>...
> > > > > hi, i am looking for a way to replicate the exact values that i get from a variable in matlab.
> > > > > i have a variable, fitmodel fm1, with the coefficients of the polynomial that fit the data. if i use the symbolic values of these coefficients in a consequent equation i get different result than if i use the numeric values of the coefficients that are showed for these variables.
> > > > > supposing the case:
> > > > > Linear model Poly9:
> > > > > fm1(x) = p1*x^9 + p2*x^8 + p3*x^7 + p4*x^6 +
> > > > > p5*x^5 + p6*x^4 + p7*x^3 + p8*x^2 + p9*x + p10
> > > > > Coefficients (with 95% confidence bounds):
> > > > > p1 = 8.32e007 (8.257e007, 8.383e007)
> > > > > p2 = 5.217e005 (5.25e005, 5.185e005)
> > > > > p3 = 0.001308 (0.001301, 0.001315)
> > > > > p4 = 0.01684 (0.01693, 0.01676)
> > > > > p5 = 0.1189 (0.1183, 0.1195)
> > > > > p6 = 0.4585 (0.461, 0.456)
> > > > > p7 = 0.9485 (0.9422, 0.9547)
> > > > > p8 = 1.185 (1.193, 1.176)
> > > > > p9 = 1.063 (1.058, 1.068)
> > > > > p10 = 0.5639 (0.565, 0.5629)
> > > > >
> > > > > i get different result if i use fm1.p1 than if i use 8.32/10^7.
> > > > > nonetheless i need to use the numerical data, not the variable itself; so i'd like to ask you about how can i extract the exact value of the variables?
> > > > > thank you so very much!
> > > > >
> > > > > Orchy
> > > >
> > > > You haven't stated what kind of fit to the data you are striving for. If you have exactly ten data points, in general an exact unique fit is possible, but if there are more, then the coefficients you obtain will depend on what sort of fit you want. This is true symbolically as well as numerically. For example, a least squares fit can be obtained using the matlab backslash operator '\' and the result of that is exact for a symbolic solution and numerically the accuracy can be to approximately one part in 1e16.
> > > >
> > > > Roger Stafford
> > >
> > >  Hi, Roger.
> > > i'm not sure i get your point. is the type of fit relevant for my issue?
> > > i use polynomial of 9 degree to fit my data whose size varies.
> > > i used the data to obtain the fit function using 9 degree polynomial. further, i want to make use of the polynomial i get.
> > > instead of using the expression
> > > pf = fm1.p1.*myx^9+fm1.p2.*myx^8+ ...
> > > i want to use
> > > pf = 8.32/(10^7)*myx^95.217/(10^5)*myx^8+...
> > >
> > > my problem appears as the second pf is different than the first pf. and more certainly that's because fm1.p1 displays a rather approximated value of the first coefficient, so , when i copy it as it is displayed on the screen, i don't get the right coefficient, but that certain approximation. i don't know how to extract the exact numerical value from fm1.p1(, and other similar coefficients).
> > > Orchy
> >
> > Orchy,
> >
> > It looks like your are talking about the output that comes out for the "fit" function from the Curve Fitting Toolbox.
> >
> > fm1.p1, fm1.p2, etc are the accurate coefficients. What's displayed on the screen will not be the exact because of the precision for the display (it's merely for display). So ideally, you should use the actual values from the fit result (fm1.p1, etc).
> >
> > My question is WHY do you need to represent it with the actual numbers? I can think of many reasons why you should NOT do that, one of which is the accuracy problem you are encountering. Another reason is that you are hardcoding the results, so if you were to reuse your code on a different data set, you have to rewrite your code. Is there a reason you cannot use the variable form (the first expression you showed)?
> >
> > If you can answer me these questions, then we can try to address your issue.
> >
> > jiro
>
> hi Jiro,
> yes, i am using the result from the Curve Fitting Toolbox . and yes, i am encountering the first issue, but not the second one.
> my goal here was to find a function with a particular property. to have that property , i knew i could come up with a sort of sinusoidal combination, however i needed to describe the function by polynomial coefficients, for some code reuse reasons. therefore, i generated data with some sinusoidal function, used curve fitting tool to have a polynomial description. now, rather than doing the same procedure everytime just to get those variables and used them , i wanted to simplify the problem by only having those numerical values in the expression of the function i am hunting. moreover, the expression has to be written eventually in C code, and there it's impossible to use any matlab function.
> so, this is the brief of the rationale.
>
> as advised above, i used 'format long' command to get more accurate values. the result now is ok, but it takes a great while to compute the values of the function, probably due to those long accurate numbers?
> but i suppose i can't avoid this.
> still i wonder why it takes longer time to compute
> pf = 8.32/(10^7)*myx^95.217/(10^5)*myx^8+...
> than it takes to compute
> pf = fm1.p1.*myx^9+fm1.p2.*myx^8+ ...
> even if at the moment the numerical coefficients have the same accuracy as the symbolic ones.
>
> thanks a lot for assistance,
> Orchy
I doubt that the increase in time (how much?) is due to the "long accurate numbers". It probably has more to do with how the MATLAB parser works when it reads in an mfile.
In the second case it simply retrieves the fm1.p1, etc. values from storage and uses it.
In the first case, my guess is it does something like set a temp1 variable to 8.32. Then set a second temp2 variable to 10^7. Then divide the two and put that result in temp3. Then retrieve temp3 as fm1.p1 use it from there as in the second case. And you have 10 of these coefficients, right?
But again, it depends on the specifics of the MATLAB parser, I could be wrong!
