Any MAth Majors or people good at math here?

Page 3 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

TuxDave

Lifer
Oct 8, 2002
10,571
3
71
Originally posted by: RaynorWolfcastle
Originally posted by: TuxDave
I'm thinking more on the lines of digital filter design.... which I guess can derive from fourier theory. I'm too lazy so I picture the problems in terms of poles and zeros. Heh...

Digital filter design => Z-transform => Good luck with all of that; parametrizing anything with Z-transforms is gonna be a interesting to say the least :p

Yeah... it's not easy without matlab. But if you're just looking for 1st order accuracy, the equation I posted above it good enough.
 

RaynorWolfcastle

Diamond Member
Feb 8, 2001
8,968
16
81
Hmm... I wrote a Maple program that solves the problem parametrically for piecewise cubic polynomials that are only "first derivative smooth". Usually you shoot for "second derivative smooth", but to solve this with cubics there simply aren't enough degrees of freedom to factor in all the constraints and get a second-derivative smooth interpolation.
 

imported_vr6

Platinum Member
Jul 6, 2001
2,740
0
0
Not sure if it helps, but check out this book called "Numerical Recipes" It has countless procedures in there dealing with numerical analyses. If you know what you need to do, the code will probably be in there with a brief explanation of the mathematics. I was able to get cublic spline interpolation from it, without knowing the math.
 

RaynorWolfcastle

Diamond Member
Feb 8, 2001
8,968
16
81
Originally posted by: Kwan1
Not sure if it helps, but check out this book called "Numerical Recipes" It has countless procedures in there dealing with numerical analyses. If you know what you need to do, the code will probably be in there with a brief explanation of the mathematics. I was able to get cublic spline interpolation from it, without knowing the math.

cubic spline interpolation isn't sufficient in this case because there are several points in which you not only have to set the 'y' value, but also the derivatives. That is at t1 and t3, you want y' = 0, which means that you don't have enough degrees of freedom to solve with cubics unless you give up second derivative smoothness at these points.
 

RaynorWolfcastle

Diamond Member
Feb 8, 2001
8,968
16
81
OK, here's the solution I posted about earlier. I have it as a Maple procedure right now, but as long as you have some math library that can row-reduce (something like Matlab's C++ library would work just fine)
here's a pic of what it can do, solution


Here's the Maple code, FWIW (how do I attach code?)

>funct := proc(t1,t2,t3,h) local ans;global f;
> ans:=rref(matrix([
> [t1^3,t1^2,0,0,0,0,0,0,0,0,h],
> [3*t1^2,2*t1,0,0,0,0,0,0,0,0,0],
> [0,0,t1^3,t1^2,t1,1,0,0,0,0,h],
> [0,0,3*t1^2,2*t1,1,0,0,0,0,0,0],
> [0,0,t2^3,t2^2,t2,1,0,0,0,0,0],
> [0,0,3*t2^2,2*t2,1,0,0,0,0,0,0],
> [0,0,0,0,0,0,t2^3,t2^2,t2,1,0],
> [0,0,0,0,0,0,3*t2^2,2*t2,1,0,0],
> [0,0,0,0,0,0,t3^3,t3^2,t3,1,h],
> [0,0,0,0,0,0,3*t3^2,2*t3,1,0,0]
> ]));
> f:=piecewise(
> x < 0, 0,
> x < t1, ans[1,11]*x^3+ans[2,11]*x^2,
> x < t2, ans[3,11]*x^3+ans[4,11]*x^2+ans[5,11]*x+ans[6,11],
> x < t3, ans[7,11]*x^3+ans[8,11]*x^2+ans[9,11]*x+ans[10,11],
> x > t3, h
> );
> plot(f,x=-2..5/4*t3,scaling=constrained);
> end proc:
 

Cerebus451

Golden Member
Nov 30, 2000
1,425
0
76
How will this function eventually be implemented? I wrote the following quick C function that takes all the necessary parameters and produces this graph. That graph was using T1 = 2, T2 = 3, T3 = 4, and H = 5 (I swapped T2 and T3 to make them linear).

Code:
double f (double x, double t1, double t2, double t3, double H)
{
if (x <= t1)
{
return H * sin (PI * x / (2 * t1));
}
else if (x <= t2)
{
return H * cos (PI * (x - t1) / (2 * (t2 - t1)));
}
else if (x <= t3)
{
return (H / (t3 - t2)) * (x - t2);
}
else
{
return H;
}
}

The only issue here is the sharp turn at T2. If you wanted that to be smoother, will take a little more time.