On 29.06.2013 21:19, Raymond Toy wrote:
> On 6/29/13 11:55 AM, Rupert Swarbrick wrote:
>> Adam <adammaj1 at o2.pl> writes:
>>> At the end it should be :
>>>
>>> I can do it using linear function , but then curve is not smooth. I
>>> would like to use nonlinear function.
>> I don't know whether Maxima has functions for smooth curve
>> fitting. Maybe other respondents can help you there. Hopefully the
>> following general pointers will be of some use to you:
>
> There's at least lbfgs and minpack_lsquares (and some Lagrange
> polynomial routine whose name I forget) to fit curves to data.
I have tried package interpol and cspline function
> But I
> think you'll have to remove the non-existent data from your data list
> yourself before using these routines.
OK, but when I remove this points then curve has a sharp bend
cspline(a)$ /* negative values are removed */
(%i9) f(x):=''%$
(%i10) draw2d(
color = red,
key = "Cubic splines",
explicit(f(x),x,0,10),
point_size = 3,
color = blue,
key = "Sample points",
points(a))$
It works but shape is different then expected
I think that I have to fill gaps earlier. In C :
// interpolated not computed ( negative values)
int FillGapsInRaysArray()
{
// indexes of the array
int i; // index of the pixel on the ray
int iMini, iMaxi; // gap border
int j; // index of the ray
double dStep;
int iStep;
// fill empty values = change negative with positive !!!!!!!!!!
// negative value = not filled = gaps
// positive value = filled ( computed )
// check every ray
for (j = 0; j < iPeriodChild ; j++)
{
// start from 0 wher are negative values
// because of slow dynamics
i=0;
// find first positive value
while (RaysTurns[i][j]<0.0) i+=1;
iMaxi = i;// here positive
// copy first positive value to all cells before it = straight line
for (i=0; i<iMaxi; i++) RaysTurns[i][j] = RaysTurns[iMaxi][j];
// go back
i = iMaxi; // positive
printf("in ray j= %d there is a gap from i= 0 to i= %d iStep = %d
; \n",j, iMaxi, iMaxi);
// rest of the array
do {
// go thru all positive
while (RaysTurns[i][j]>0.0 && i<iMaxDistance2Alfa-1) i+=1;
iMini=i-1; // here is positive, lower border of the gap
// here value is negative : RaysTurns[i][j]<0.0
do i+=1; while (RaysTurns[i][j]<0.0 && i<iMaxDistance2Alfa-1 );
iMaxi= i; // positive , upper border of the gap
iStep= iMaxi-iMini;
// step between RaysTurns[iMini][j] and RaysTurns[iMaxi][j]
if (RaysTurns[iMaxi][j]>RaysTurns[iMini][j] )
dStep = (RaysTurns[iMaxi][j]-RaysTurns[iMini][j])/iStep;
else dStep = (RaysTurns[iMini][j]-RaysTurns[iMaxi][j])/iStep;
// step between values
if (iMaxi<iMaxDistance2Alfa-1 && RaysTurns[iMaxi-1][j]< 0.0) //
array is numberd from 0 to ...
{
printf("in ray j= %d there is a gap from i= %d to i= %d
iStep = %d ; dStep = %f\n",j, iMini, iMaxi, iStep, dStep );
// fill the gap
i= iMini;
// while (i<iMaxi-1) { i+=1;
RaysTurns[i][j]=RaysTurns[iMini][j] + (i-iMini)*dStep;}
i=iMaxi;
}
else {
printf("in ray j= %d there is a gap from i= %d to i= %d iStep
= %d ; \n",j, iMini, iMaxi, iStep);
// copy last positive value to all cells after it = straight
line
for (i=iMini+1; i<iMaxi; i++) RaysTurns[i][j] =
RaysTurns[iMini][j];
}
} while (i<iMaxDistance2Alfa);
} // j
return 0;
}
Adam