What is C2 surface in CAD, what does C2 mean? - opengl

C2 surface/mesh is well-known surface in CAD/OpenGL. But I just want to know that what is C2 means ?
C means what ?
2 means what ?
C2 = acronym ???????

Continuous in the second derivative.
Generally you'll see it used when discussing various splines.

Related

Minimum between two boolean decision variables in Pyomo

I need to do something like this:
d1 == min(d2,d3)
where d is a decision variable. I need to use Pyomo. In cplex the solution is achieved by the funnction minl, how can do this in Pyomo or in an equivalent linear form?
I searched for a solution on Google and found that I could assert that d1 must be less or equal to d2 and d3. But this do not fit my proble, because if d2 and d3 is equal to 1, d1 <= 1 while I need d1 == 1.
Thanks for replies.
When the d variables are binary variables,
d1 = min(d2,d3)
is really the same as multiplication
d1 = d2*d3
This is often linearized as
d1 <= d2
d1 <= d3
d1 >= d2+d3-1

sympy dsolve returns incorrect answer

I'm using sympy.dsolve to solve a simple ODE for a decay chain.
The answer I get for different decay rates (e.g. lambda_1 > lambda_2) is wrong. After substituting C1=0, I get a simple exponential
-N_0*lambda_1*exp(-lambda_1*t)/(lambda_1 - lambda_2)
instead of the correct answer which has:
(exp(-lambda_1*t)-exp(-lambda_2*t)).
What am I doing wrong?
Here is my code
sp.var('lambda_1,lambda_2 t')
sp.var('N_0')
daughter = sp.Function('N2',Positive=True)(t)
stage1 = N_0*sp.exp(-lambda_1*t)
eq = sp.Eq(daughter.diff(t),stage1*lambda_1 - daughter*lambda_2)
sp.dsolve(eq,daughter)
Your differential equation is (using shorter variable identifiers)
y' = A*N0*exp(-A*t) - B*y
Apply the integrating factor exp(B*t) to get the equivalent
(exp(B*t)*y(t))' = A*N0*exp((B-A)*t)
Integrate to get
exp(B*t)*y(t) = A*N0*exp((B-A)*t)/(B-A) + C
y(t) = A*N0*exp(-A*t)/(B-A) + C*exp(-B*t)
which is exactly what the solver computed.
Did you plug in C1 = 0, expecting to get a solution such that y(0) = 0? That's not how it works. C1 is an arbitrary constant in the formula, setting it to 0 is no guarantee that the expression will evaluate to 0 when t = 0.
Here is a correct approach, step by step
sol1 = sp.dsolve(eq, daughter)
This returns a Piecewise because it's not known if two lambdas are equal:
Eq(N2(t), (C1 + N_0*lambda_1*Piecewise((t, Eq(lambda_2, lambda_1)), (-exp(lambda_2*t)/(lambda_1*exp(lambda_1*t) - lambda_2*exp(lambda_1*t)), True)))*exp(-lambda_2*t))
We can clarify that they are not:
sol2 = sol1.subs(Eq(lambda_2, lambda_1), False)
getting
Eq(N2(t), (C1 - N_0*lambda_1*exp(lambda_2*t)/(lambda_1*exp(lambda_1*t) - lambda_2*exp(lambda_1*t)))*exp(-lambda_2*t))
Next, we need C1 such that the right hand side turns into 0 when t = 0. So, take the right hand side, plug 0 for t, solve for C1:
C1 = Symbol('C1')
C1val = solve(sol2.rhs.subs(t, 0), C1, dict=True)[0][C1]
(It's not necessary to include dict=True but I like it, because it enforces uniform output of solve: it's an array of dictionaries.)
By the way, C1val is now N_0*lambda_1/(lambda_1 - lambda_2). Put it in:
sol3 = sol2.subs(C1, C1val).simplify()
and there you have it:
Eq(N2(t), N_0*lambda_1*(exp(lambda_1*t) - exp(lambda_2*t))*exp(-t*(lambda_1 + lambda_2))/(lambda_1 - lambda_2))
The expression is equivalent to N_0*lambda_1*(exp(-lambda_2*t) - exp(-lambda_1*t))/(lambda_1 - lambda_2) although SymPy seems loathe to combine the exponentials here.

Predict data values given history and constraints

If I have data series and a set of constraints and want to predict the most likely values, what is the right algorithm or approach? For example, given the data table as follows:
The first three rows illustrate typical data values. Imagine we have dozens or hundreds of such rows. The constraints on the system are as follows:
G1 + G2 + G3 + G4 == D1 + D2 + D3
G1 + G2 = D1 - C1
G3 = D2 + C1 - C2
G4 = D3 + C2
So, given D1, D2 and D3 we need to predict G1, G2, G3, G4, C1, and C2. Note that there may not necessarily be enough information to solve the system by linear programming alone and so some kind of trend analysis or probability distribution might need to be made.
What is the right algorithm or approach to solve a problem like this?

Linear Interpolation Optimization For Sign-ness

In a tight loop, I am doing a linear interpolation between two floating point values. However, the only necessary part of the result is the sign (whether the result is negative or positive). I'm doing a typical lerp operation right now, f way between a and b.
a + f * (b - a);
Is there something more efficient considering I just need to know the resulting sign and not the actual lerped value?
Edit: 'f' is a set of fixed distances along the interpolation, which are known beforehand.
You can calculate whether interpolated value changes sign at given range:
if Sign(a) <> Sign(b) then //don't forget about zero sign
change occurs
In this case find f parameter, where lerp = 0
a + f0 * (b - a) = 0
f0 = a / (a+b)
For smaller values lerp has the same sign as a, for larger - the same sign as b, so you don't need to calculate lerp value - just compare f with f0

Bresenham's algorithm

How to find the decision parameter for drawing different functions like parabola, sine curve, bell curve?
Please tell me about the approach why do we sometimes multiply by constant?
For Example
in case of ellipse, p = a^2(d1 - d2),p = b^2(d1 - d2) for upper and lower half region
respectively where a, b constants
in case of line, p = deltax(d1 - d2) where p is decision parameter d1,d2 are
distances,deltax is constant and is equal to xend - xstart
why not only take (d1 -d2) as parameter
Bresenham's algorithm as stated by the OP is a bit amiss, but I assume the following.
The decision parameter could adjust d1 - d2 and not scale by some constant as you suggest were it not for the initialization of the decision parameter. It is not generally scalable by that constant.
// code from http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
plotLine(x0,y0, x1,y1)
dx=x1-x0
dy=y1-y0
D = 2*dy - dx // Not scalable by 2
plot(x0,y0)
y=y0
for x from x0+1 to x1
if D > 0
y = y+1
plot(x,y)
D = D + (2*dy-2*dx) // Scalable by 2
else
plot(x,y)
D = D + (2*dy) // Scalable by 2